matlab中for循环语句使用问题。

8 ビュー (過去 30 日間)
各位大佬求提问,我写了一个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

採用された回答

威尼斯遇到平台系统抽查稽核不能出款要怎么解决?【微81923899】
仅供参考,试试
clc
clear all
load('data1.mat')
A = data5;   %A需要为112280*n的矩阵
A = A(:);
f = 200000;   %定义数据结果频率0.01s算一次
X = zeros(30,2);
for r=1:30
    time_stamp = 0.01 * r;
   
    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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange编程 についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!