繁体   English   中英

如何在Matlab中计算均值,最小值和最大值

[英]How to calculate the mean, min and max in matlab

因此,我有一个脚本,可根据加速器数据计算平均值:

clear all
close all
clc

load 'results.txt'
Fq=51.2;
N=length(results);

t= [1:N]/Fq;

plot (t,results);

role=results;
lowrow=role(1:9244,:);
fly=role(9245:18700,:);
pull=role(18802:28171,:);

subplot(3,1,1)
plot(lowrow)
xlabel('Samples'); ylabel('Acceleration'); title('High to Low Rows')
subplot(3,1,2)
plot(fly)
xlabel('Samples'); ylabel('Acceleration'); title('Reverse Fly')
subplot(3,1,3)
plot(pull)
xlabel('Samples'); ylabel('Acceleration'); title('Lawn Mower Pull')

windowLength = 5; %Length for each window in seconds
startPos = 1; %Starting Position for 1st win
endPos = startPos + (windowLength * floor(Fq)); %End Position for 1st win
totalWindows = floor(length(lowrow)/Fq/windowLength);

stats = zeros(windowLength,9);

for i = 1:totalWindows
epMean = mean(lowrow(startPos:endPos,:)); %calculate window mean

%X, Y & Z axis values for each stat
lowrowfeatures(i,1:3) = epMean; 

%Next window position
startPos = endPos+1;
endPos = startPos + (windowLength * floor(Fq));
end
windowLength = 5; %Length for each window in seconds
startPos = 1; %Starting Position for 1st win
endPos = startPos + (windowLength * floor(Fq)); %End Position for 1st win
totalWindows = floor(length(fly)/Fq/windowLength);

stats = zeros(windowLength,9);

for i = 1:totalWindows
epMean = mean(fly(startPos:endPos,:)); %calculate window mean

%X, Y & Z axis values for each stat
flyfeatures(i,1:3) = epMean; 

%Next window position
startPos = endPos+1;
endPos = startPos + (windowLength * floor(Fq));
end
windowLength = 5; %Length for each window in seconds
startPos = 1; %Starting Position for 1st win
endPos = startPos + (windowLength * floor(Fq)); %End Position for 1st win
totalWindows = floor(length(pull)/Fq/windowLength);

stats = zeros(windowLength,9);

for i = 1:totalWindows
epMean = mean(pull(startPos:endPos,:)); %calculate window mean

%X, Y & Z axis values for each stat
pullfeatures(i,1:3) = epMean; 

%Next window position
startPos = endPos+1;
endPos = startPos + (windowLength * floor(Fq));
end


save('wekafile.txt','lowrowfeatures','flyfeatures','pullfeatures','-ascii')

我知道均值,最小值和最大值均应位于一个脚本中,但我不确定如何执行此操作。 然后,我将其作为arff文件放入weka中,以查看j48树。

亲切的问候 :)

我不确定我是否理解这个问题,但是MATLAB具有一个内置函数,用于计算minmax ,就像均值一样。 采用;

minimum = min(variable);
maximum = max(variable);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM