【发布时间】:2016-09-15 03:14:04
【问题描述】:
所以我有一个脚本可以根据加速器数据计算平均值:
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 树。
亲切的问候:)
【问题讨论】:
-
你不能只是转储一堆代码(甚至没有缩进!)然后询问如何执行完全微不足道的任务,甚至不提及代码中的位置以及要执行这些计算的变量.
mean、min和max都是 MATLAB 内置函数,那么您到底遇到了什么问题? -
丹,谢谢您的回复。我遇到的问题是我的问题:)
-
如果是这样,那么它被深深地埋在了无格式和不相关的代码中,没有人会找到它。阅读How to Ask 以及如何创建MCVE。在您的情况下,您需要专注于 M(为了最小化,删除所有不相关的代码)。