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

8 vues (au cours des 30 derniers jours)
Michael le 12 Sep 2023
Commenté : Michael le 12 Sep 2023
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!
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Mario Malic le 12 Sep 2023
Modifié(e) : Mario Malic le 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
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Michael le 12 Sep 2023
Thank you so much, I was going insane trying to make that work!!

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by