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

5 ビュー (過去 30 日間)
Michael 2023 年 9 月 12 日
コメント済み: Michael 2023 年 9 月 12 日
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!

サインインしてコメントする。

### 採用された回答

Mario Malic 2023 年 9 月 12 日

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 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Michael 2023 年 9 月 12 日
Thank you so much, I was going insane trying to make that work!!

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by