MATLAB: How to get the for loop working

for loop

Hi,
I want to fill an empty matrix with values that equal the size of other matrices, being muscles. I tried looping over the different muscles, but the loop gives me a matrix with 6 times the size of last muscle, instead of 6 different numbers.
Here's my code:
Names2 = {'soleus', 'tibant', 'gaslat', 'vaslat', 'rectfem', 'hamlat'};
Vars2 = {soleus, tibant, gaslat, vaslat, rectfem, hamlat};
nvars = length(Vars2);
Duration = zeros(6,3);
for s = 1 : nvars
for d = 1:6
Duration(d,1) = length(IndexMuscleActGait.(names2{s}));
end
end
This gives me a matrix with in the first colum 6 times the number 50, which equals length of IndexMuscleActGait of the last muscle. However, I want the length of the 6 different muscles, and I can't find the right command to get it working.

Best Answer

for s = 1 : nvars
Duration(s,1) = length(IndexMuscleActGait.(names2{s}));
end