フィルターのクリア

Find peaks in a for loop?

2 ビュー (過去 30 日間)
Troth
Troth 2022 年 10 月 26 日
回答済み: Star Strider 2022 年 10 月 26 日
i have a 1007x94 matrix, how would I write a for loop to find the peak in every row?

採用された回答

Star Strider
Star Strider 2022 年 10 月 26 日
The maxk and mink functions (introduced in R2017b) would make this a bit more efficient. Lacking them, use sort.
Try this —
A = randn(1007, 94);
for k = 1:size(A,2)
[pks, locs] = findpeaks(A(:,k));
[~,ix] = sort(pks);
minpk{:,k} = [pks(ix(1:2)) locs(ix(1:2))];
maxpk{:,k} = [pks(ix(end-1:end)) locs(ix(end-1:end))];
end
maxpk{1} % View Result
ans = 2×2
3.0201 816.0000 3.3828 355.0000
minpk{1} % View Result
ans = 2×2
-1.0253 384.0000 -0.9567 702.0000
.

その他の回答 (1 件)

Vasudev Sridhar
Vasudev Sridhar 2022 年 10 月 26 日
Assuming you mean maximum when you say peak.
a = randi(20, 2,10)
a = 2×10
15 18 17 14 2 6 17 1 7 9 6 17 18 18 4 5 17 19 1 18
result = max(a,[],2)
result = 2×1
18 19
  1 件のコメント
Troth
Troth 2022 年 10 月 26 日
My goal is to write a loop to find the 2 highest peaks and two lowest of each column (not row I made a mistake) and each index which it occurs, but to use the find peaks function to do so.

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

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by