save data from a for loop - problems with size
Show older comments
I need to make a loop with a lot of calculations. If I just perform the loop, everything is fine, I get a result. The problem is that I want the results for all datapoints and not just the last one. I tried the tricks that I found online but it doesn't work. This is the normal code:
for i= 1:202;
origin2=(LE(:,i)+ME(:,i))/2;
Y2=(FH(:,i)-origin2)/norm(FH(:,i)-origin2);
ztemp2=(FH(:,i)-ME(:,i))/norm(FH(:,i)-ME(:,i));
x2=cross(Y2,ztemp2);
X2=x2/norm(x2);
z2=cross(X2,Y2);
Z2=z2/norm(z2);
R2=[X2 Y2 Z2];
midpoint=(LM(:,i)+MM(:,i))/2;
mid=(MLP(:,i)+MMP(:,i))/2;
Y3=(mid-midpoint)/norm(mid-midpoint);
ztemp3=(LM(:,i)-MM(:,i))/norm(LM(:,i)-MM(:,i));
x3=cross(Y3,ztemp3);
X3=x3/norm(x3);
z3=cross(X3,Y3);
Z3=z3
norm(z3);
R3=[X3 Y3 Z3];
end
relor=inv(R2)*R3
In the end I get a matrix for relor, this is good, its what I want. The problem is that I want results for all timepoints (so 202 results in total) to put it in a plot. Every time I put
R2(i)=[X2 Y2 Z2];
in it it gives an error that 'In an assignment A(I) = B, the number of elements in B and I must be the same !'
I don't know how to make it work, can somebody help ? !
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!