필터 지우기
필터 지우기

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 CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by