Find peaks in a for loop?
3 次查看(过去 30 天)
显示 更早的评论
i have a 1007x94 matrix, how would I write a for loop to find the peak in every row?
0 个评论
采纳的回答
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
minpk{1} % View Result
.
0 个评论
更多回答(1 个)
Vasudev Sridhar
2022-10-26
Assuming you mean maximum when you say peak.
a = randi(20, 2,10)
result = max(a,[],2)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!