error in returning widths over iterated findpeaks

1 回表示 (過去 30 日間)
Teddy Fisher
Teddy Fisher 2020 年 1 月 15 日
回答済み: Raunak Gupta 2020 年 1 月 23 日
Hi,
I am trying to use findpeaks over a matrix, x, column by column. I am using a for loop as below:
for k=1:size(x,2)
[P{k},locs{k},widths,proms{k}]=findpeaks(x(:,k))
end
Everything is working fine except for returning widths. P, locs and proms all return as cell arrays with all the data for the peaks in each column. However, widths only returns the widths of the peaks for the last column. When I try to edit it by making widths return as a cell array:
for k=1:size(x,2)
[P{k},locs{k},widths{k},proms{k}]=findpeaks(x(:,k))
end
I get the error message "Cell contents assignment to a non-cell array object"
Is there a way to get this function to return all the widths of all the peaks for each column?
  2 件のコメント
Image Analyst
Image Analyst 2020 年 1 月 15 日
編集済み: Image Analyst 2020 年 1 月 15 日
Can you make it easy for us to help you by attaching your x in a .mat file with the paper clip icon?
save('answers.mat', 'x')
What I tried just worked fine:
x = 100 * rand(20, 5);
for k=1:size(x,2)
fprintf('\n============================\nGetting data for column %d...\n', k);
[P{k},locs{k},widths{k},proms{k}]=findpeaks(x(:,k))
end
Teddy Fisher
Teddy Fisher 2020 年 1 月 15 日
Yes here it is attached.
I'm not sure what that line you added in does, could you explain that a bit?

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

採用された回答

Raunak Gupta
Raunak Gupta 2020 年 1 月 23 日
Hi,
I tried with the Release R2017b that is mentioned in question and with the latest Release that is R2019b but didn’t find any issues while running the code. Still I guess you may try pre declare the variables that are returned from findpeaks as below.
P = cell(1,size(deltaFoFCopy,2));
locs = cell(1,size(deltaFoFCopy,2));
widths = cell(1,size(deltaFoFCopy,2));
proms = cell(1,size(deltaFoFCopy,2));
Also, from the data file I can see that some columns are entirely zero so for those only empty vectors will return. Therefore, for some indexes in cell array the value will be empty vectors.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by