findpeak for every column of a matrix

14 ビュー (過去 30 日間)
Rafi.P
Rafi.P 2020 年 7 月 27 日
コメント済み: Rafi.P 2020 年 7 月 27 日
i have one issue, i have matrix 760x5 how to findpeaks for every column without having to write findpeak in each column
this is the example coding that I used :
[pks1_p,loc1_p] = findpeaks(y_p(:,1),'MinPeakHeight',0.09,'MinPeakDistance',100);
[pks2_p,loc2_p] = findpeaks(y_p(:,2),'MinPeakHeight',0.09,'MinPeakDistance',100);
[pks3_p,loc3_p] = findpeaks(y_p(:,3),'MinPeakHeight',0.09,'MinPeakDistance',100);
[pks4_p,loc4_p] = findpeaks(y_p(:,4),'MinPeakHeight',0.09,'MinPeakDistance',100);
[pks5_p,loc5_p] = findpeaks(y_p(:,5),'MinPeakHeight',0.09,'MinPeakDistance',100);
the problem is I have to write findpeak one by one to see the value of each column. how to get findpeak to follow the number of columns that exist without having to be written one by one
but I need values ​​from pks and loc of each column in the workspace :

採用された回答

Mohammad Sami
Mohammad Sami 2020 年 7 月 27 日
You can use size(y_p,2) to find how many columns there are in your data.
Thereafter you can either use a for loop or arrayfun to iterate over the columns.
[pks_p,loc_p] = arrayfun(@(col)findpeaks(y_p(:,col),'MinPeakHeight',0.09,'MinPeakDistance',100),1:size(y_p,2),'UniformOutput',false);
% pks_p, loc_p would be cell arrays. index 1 will correspond to column 1 and so on
  3 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 7 月 27 日
you mean you want them to appear in workspace ?
i would suggest use indexing to access the data from each col.
% example
for i = 1:length(pks_p)
pksi_p = pks_p{i};
loci_p = loc_p{i};
% do something
end
Rafi.P
Rafi.P 2020 年 7 月 27 日
Thank you Mohammad Sami

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2020 年 7 月 27 日
Consider using islocalmax with the dim input argument.

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by