MATLAB Answers

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

2 views (last 30 days)
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.

  0 Comments

Sign in to comment.

Accepted Answer

David Hill
David Hill on 16 Jun 2020
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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!