How to manipulate cell array values of arrays with different lengths?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kimberly Cardillo
le 16 Juin 2020
Réponse apportée : David Hill
le 16 Juin 2020
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/317145/image.jpeg)
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 commentaires
Réponse acceptée
David Hill
le 16 Juin 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 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!