Clear Filters
Clear Filters

I'm trying to use the findpeaks function in a for-loop for a large array and struggling to generate multiple outputs

4 views (last 30 days)
Hello all,
I'm super new to matlab and have a (hopefully) basic question. I have a 23 row array and a predetermined threshold and I'm trying to evaluate the peaks per row. I, unfortunately, am only able to generate one output instead of 23 currently. I have the beginnings of some code below for array "dff"
for i=1:size(dff, 1)
[pks,locs]=findpeaks(dff(i,:), 2, 'MinPeakHeight', threshold(i));
end
In a perfect world I would have a 2 arrays at the end of this called "pksdata" and "locsdata" that would have 23 rows of information each. I apologize if this is an annoying question!

Accepted Answer

Mario Malic
Mario Malic on 12 Sep 2023
Edited: Mario Malic on 12 Sep 2023
Hey,
If I understood correctly your question, you should use a cell array due to numeric array limitations which is that numeric array has to have equal number of columns in the same row and vice versa. Iit is not possible to do it with a numeric array because there might be different number of peaks in each row. You can squeeze your peaks and locations into a single element of cell array for each row like shown below.
pks = cell(size(dff, 1), 1);
locs = cell(size(dff, 1), 1);
for i=1:size(dff, 1)
[pks{i},locs{i}]=findpeaks(dff(i,:), 2, 'MinPeakHeight', threshold(i));
end

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!