I am trying to use a for loop to make some calculations in a cell array but at the end only the results for the last loop are displayed. I would like Matlab to display the results for all loops. Here there is the code:
slope=[];
time=[];
position= [];
for p=1:max(L) % max L gives the number of result{n}. so if max(L)=6 we have from result{1} to result{6} and therefore 6 final values that i want to get%
a=result{n}(:,1);
b=result{n}(:,2);
end
B = [ones(length(a),1) a] \ b % this is to obtain the slope and intercept of a lin. regresion
slope = B(2)
time = result{n}(end,1)-result{n}(1:1)
position = (slope.*result{n}(end,1)+intercept)-(slope.*result{n}(1:1)+intercept)
At the moment in the output that is what i get:
slope =
4.4089
time =
0.5794
position =
2.5546
This result is correct. However, these values are the ones obtained with result{6} and i need the values previous to this one.
Any help is much appreciated !
Thanks in advance!