how to save each loop variable in the same vector?

hello, every one i have question
i make a loop code to get vi, fi
but, i want to save this vi fi data in the same vector
please let me know how to save result of vi and fi in same vector,
thank you,
%data set = x
n = 24;
for i = 1:numel(x)-n+1
xi = x(i:i+23);
envelope(xi,1,'peak')
[peakHeights,valleyHeights] = envelope(xi,1,'peak')
vi = sum(peakHeights-valleyHeights);
[peakHeights, indexesOfPeaks] = findpeaks (xi);
[valleyHeights, indexesOfValleys] = findpeaks (xi);
fi = [numel(indexesOfPeaks) + numel(indexesOfValleys)]
end

 採用された回答

Walter Roberson
Walter Roberson 2020 年 10 月 16 日

0 投票

%data set = x
n = 24;
M = numel(x)-n+1;
all_vi = zeros(1,M);
all_fi = zeros(1,M);
for i = 1:M
xi = x(i:i+23);
envelope(xi,1,'peak');
[peakHeights,valleyHeights] = envelope(xi,1,'peak');
vi = sum(peakHeights-valleyHeights);
[peakHeights, indexesOfPeaks] = findpeaks (xi);
[valleyHeights, indexesOfValleys] = findpeaks (xi);
fi = numel(indexesOfPeaks) + numel(indexesOfValleys);
all_vi(i) = vi;
all_fi(i) = fi;
end

1 件のコメント

HAN TAEHEE
HAN TAEHEE 2020 年 10 月 16 日
thank you very much! it works!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSignal Generation, Analysis, and Preprocessing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by