Cell computations - for loop

7 Ansichten (letzte 30 Tage)
Uerm
Uerm am 14 Okt. 2019
Beantwortet: Uerm am 17 Okt. 2019
Hi, I have a variable RRI, which is a 1x48 cell, each cell being matrices of different sizes.
m = 0;
for num = 1:length(RRI{1,1})-1
if (RRI{1,1}(num+1)-RRI{1,1}(num) > 50*10^(-3)*360)
m = m+1;
end
end
The code above works perfectly fine for one of the cells and when I do the computations individually for each cell. How can I (in a for loop for instance) do this for all 48 cells (RRI{1,i}, i = 1:48) and store the results in the variable m, which should also be a 1x48 cell?
Thanks!

Akzeptierte Antwort

Samatha Aleti
Samatha Aleti am 17 Okt. 2019
You can add another “for” loop and use a cell array to store the result. Folllowings a sample code:
m = repmat({zeros(1,1)},1,48) ; % Initialize
for i=1:length(RRI)
n = 0;
for num = 1:length(RRI{1,i})-1
if (RRI{1,i}(num+1)-RRI{1,i}(num) > 50*10^(-3)*360)
n = n+1;
end
end
m{i} = n;
end
  1 Kommentar
Uerm
Uerm am 17 Okt. 2019
Thank you very much. It works perfectly!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Uerm
Uerm am 17 Okt. 2019
Thank you. Your solution works!
How can I do the same for the following (see attached image): RRIseg is a 1x48 cell containing matrices of ROWx127. For all the cells, I want to compute exactly the same thing as above but along the rows of each matrix. For instance, if cell 1 is a 34x127 matrix, the result should be a 34x1 vector. How can I do that? Is it by using cellfun?

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by