findpeaks for different thresholds

3 ビュー (過去 30 日間)
AHN
AHN 2019 年 1 月 23 日
コメント済み: AHN 2019 年 1 月 25 日
Hi,
I am trying to find pks and locs for different threshold values. For one threshold value, this has worked fine. But for different threshold values (randomly generated), is there a way to store all the values of pks and locs? I would ideally like, for example, for threshold=x1, results in [pks1,locs1] format..for threshold=x2, results in [pks2,locs2] format and so on. Please let me know.
Thank you!
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 1 月 23 日
Cell array ?
AHN
AHN 2019 年 1 月 23 日
Thank you very much for the reply. Yes, cell array did work. But how to store all values in a for-loop in a cell array?
for Threshold1=linspace(x1,x2,n)
[pks1,locs1] = findpeaks(data);
Results(1).Threshold1 = Threshold1;
Results(1).pks1 = pks1;
Results(1).locs1 = locs1;
end
This code just stores the last values of the iteration.

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 1 月 23 日
Thresholds = linspace(x1,x2,n);
for thresh_idx = 1 : length(Thresholds)
Threshold1=linspace(x1,x2,n);
[pks, locs] = findpeaks(data, 'MinPeakHeight', Threshold1);
Results(thresh_idx).Threshold1 = Threshold1;
Results(thresh_idx).pks1 = pks;
Results(thresh_idx).locs1 = locs;
end
  1 件のコメント
AHN
AHN 2019 年 1 月 25 日
Thank you for a head start on this, was my first time with cell arrays. The above code again stored only the last values of the iteration. However, managed to solve it with the edited code below. Thanks again.
Thresholds=linspace(x1,x2,n);
for thresh_idx = 1 : length(Thresholds);
[pks,locs] = findpeaks(data,'MinPeakHeight',Thresholds(thresh_idx));
Results{thresh_idx}={Thresholds(thresh_idx),[pks,locs]};
end

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by