matlab中for循环语句使用问题。
Show older comments
各位大佬求提问,我写了一个for循环,但是我生成的矩阵X一直没有变化,这是为啥啊:(
clc
clear all
load('data1.mat')
A = data5; %A需要为112280*n的矩阵
A = A(:);
f = 200000; %定义数据结果频率0.01s算一次
for r=1:30
time_stamp = 0.01 * r;
X = zeros(30,2);
threshold=2000;
if A(1 + (r-1) * f)<threshold
flag=0;
else
flag=1;
end
old=A(1 + (r-1) * f);
new=A(2 + (r-1) * f);
count=0;
for t=1:f %2022是随便取的,看X1数据量而定
new=A(t + (r-1) * f);
%上升沿
if(new>threshold)&&(old<=threshold)&&(flag==0)
flag=1;
count=count+1;
end
%下降沿
if(new<threshold)&&(old>=threshold)&&(flag==1)
flag=0;
end
old=new;
end
X(r,1) = time_stamp;
X(r,2) = count;
end
Accepted Answer
More Answers (0)
Categories
Find more on 编程 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!