Finding peaks greater than a set value

9 次查看(过去 30 天)
I'm using
for h2 = 1:size(udata,1);
[pks,locs] = findpeaks(udata(h2, :), x);
pksc{h2,:} = pks; % Cell Array Of Peak Values
locsc{h2,:} = locs; % Cell Array Of Location Values
end
Lv = cellfun(@(x)(x < 1.9) & (x > 0.5), pksc, 'Unif',0);
% this line needs to be changed so that we can detect peaks 2*la^2 < peak
% < 0.5, basically isolate the step.
pksm = cellfun(@(x,y)x(y), pksc, Lv, 'Unif',0); % Peak Values Result
locsm = cellfun(@(x,y)x(y), locsc, Lv, 'Unif',0);
to find peaks with amplitudes >= 1.9 but when I run this code, the cell array is just 1x0 empties. Any ideas?

采纳的回答

Star Strider
Star Strider 2023-2-13
Any ideas?
Yes.
None of the identified peaks meet the criteria you set.
See my latest Comment to your earlier post How can I rewrite this to get peak locations? on how to deal with that.
.

更多回答(1 个)

Image Analyst
Image Analyst 2023-2-13
I don't think using colon as the second index will work unless pksc and locsc have been preallocated as 1-D vectors. It will not fill out a 2-D matrix with multiple columns with info from one peak in each separate column, like you're probably thinking. Also findpeaks.
pks is an array that may have different number of elements depending on how many peaks were in each row of udata. So it just goes into one cell. See the FAQ: https://matlab.fandom.com/wiki/FAQ#What_is_a_cell_array?
Also, findpeaks has a 'MinPeakHeight' option that you can use to find only peaks higher than a certain value so you can skip the cellfun stuff.
[rows, columns] = size(udata);
% Make a cell array for the output.
ca = cell(rows, 2); % Col 1 = peak values array, col 2 = indexes array.
for row = 1 : rows
[peakValues, indexesOfPeaks] = findpeaks(udata(row, :), 'MinPeakHeight', 0.5);
% Put peak values into column 1 of cell array and
% indexes into column 2 of cell array.
ca{row, 1} = peakValues; % Cell Array Of Peak Values
ca{row, 2} = indexesOfPeaks; % Cell Array Of Location Values
end

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by