フィルターのクリア

Split array into sub arrays and apply function

1 回表示 (過去 30 日間)
Priscilla
Priscilla 2020 年 7 月 15 日
コメント済み: Priscilla 2020 年 7 月 15 日
Hi everyone,
I am using findpeaks to detect peaks in my data and would like to create a sub arrays everytime a peak is detected and then apply a function to the sub arrays for example
If
x = [0.2954 0.0861 -0.0204 0.0046 0.2297 0.7651 -0.4482 -1.2974 0.3673 -0.7759 0.5676 1.0851 0.4082 0.3364 -0.3396 -0.1935 0.5228]
Peaks = [0.7651 0.5676 0.5228]
expected output / sub arrays = [{0.2954 0.0861 -0.0204 0.0046 0.2297 0.7651} {-0.4482 -1.2974 0.3673 -0.7759 0.5676} {1.0851 0.4082 0.3364 -0.3396 -0.1935 0.5228}
Thanks in advance
Regards,
Abigail
  1 件のコメント
Stephen23
Stephen23 2020 年 7 月 15 日
編集済み: Stephen23 2020 年 7 月 15 日
If you obtain findpeaks second output argument (the indices) your task will be a lot easier:

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

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 15 日
[lo, ii] = ismember(PeakS, x);
ix = diff([0, ii(lo)]);
Output = mat2cell(x, 1, ix)
  2 件のコメント
madhan ravi
madhan ravi 2020 年 7 月 15 日
As Stephen comments if you use the second output of findpeaks() you replace ii(lo) in my code with the second output of findpeaks().
Priscilla
Priscilla 2020 年 7 月 15 日
Thank you so much

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

その他の回答 (1 件)

Parth Dethaliya
Parth Dethaliya 2020 年 7 月 15 日
編集済み: Parth Dethaliya 2020 年 7 月 15 日
x = [0.2954 0.0861 -0.0204 0.0046 0.2297 ...
0.7651 -0.4482 -1.2974 0.3673 -0.7759 ...
0.5676 1.0851 0.4082 0.3364 -0.3396 -0.1935 0.5228];
Peaks = [0.7651 0.5676 0.5228];
SubArray=cell(1,size(Peaks,2));
Init=1;
for i=1:size(Peaks,2)
SubArray{i} = x(Init:find(x==Peaks(i)));
Init = find(x==Peaks(i))+1;
end
Seems the code is self-explanatory, still comment if you have any queries.
Hope it helps!!

カテゴリ

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