Can't sort coordinates of peaks found in a 2D array

3 views (last 30 days)
Hi everybody,
here's the mesh of a 2D matrix i'm working on. Matrix name is disp_curve.
As you can see, there are two groups of peaks. I have to find peaks coordinates and sort them in different columns of an array of coordinates, depending on the group they belong to. I've tried some user-made peak finders like extrema2.m, but it seems that they can't do the job. I've obained best results by implementing findpeaks in a for loop.
M = 2; %number of groups
[ nF, nK ] = size(disp_curve);
for i = 1:nF
[pks, loc] = findpeaks(abs(disp_curve(i,:)),'NPeaks', M, 'SortStr','descend');
peak_coord{i} = loc;
end
coord = zeros(nF, M);
for j = 1:nF
coord(j,1) = peak_coord{j}(1);
coord(j,2) = peak_coord{j}(2);
end
The code recognizes peaks correctly but sorts them in descending order, which may not be the correct one. I've also tried to implement 'MinPeakHeight' while removing 'SortStr' but then I get dimension mismatch errors when filling "modes" array, as there are a lot of rows where maximum value is under threshold (i.e. there's only one peak or no peaks at all). Any help is much appreciated.
Best regards
Stefano Fiorentini

Answers (0)

Community Treasure Hunt

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

Start Hunting!