How to manipulate cell array values of arrays with different lengths?

3 ビュー (過去 30 日間)
Kimberly Cardillo
Kimberly Cardillo 2020 年 6 月 16 日
回答済み: David Hill 2020 年 6 月 16 日
I have a cell array of peaks from a dataset matrix that is 5119x102 called CH1WaveForm_1. I have found the peaks for certain values within the matrix that have a value greater than 10 as seen in the code below.
for i=1:size(CH1WaveForm_1,2)
[timePks{i},timeLocs{i}]=findpeaks(CH1WaveForm_1(1200:1450,i));
for k=1:length(timePks)
newCell{k}=timePks{k}(timePks{k}>10);
end
end
My newCell{k} is 1x102 and each cell has a different array length as seen in the picture below.
I want to create a new vector that gives the ratio of the first row divided by the second row for each cell array. If there is no value/only one value in the cell array then I want the value to be equal to zero in this new vector.

採用された回答

David Hill
David Hill 2020 年 6 月 16 日
for k=1:length(newCell)
if numel(newCell{k})<2
m(k)=0;
else
m(k)=newCell{k}(1)/newCell{k}(2);
end
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