## Cell computations - for loop

on 14 Oct 2019

on 17 Oct 2019

### Samatha Aleti (view profile)

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!

### Samatha Aleti (view profile)

2019 年 10 月 17 日
採用された回答

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

Uerm

### Uerm (view profile)

on 17 Oct 2019
Thank you very much. It works perfectly!

2019 年 10 月 17 日