matlab - Saving arrays of every iteration of for loop -
i have following matlab code:
clc; clear all; close all; format long; d=717; r1=60000; r2=[61043; 62000]; rx=[0; 10]; ry=[11.212; 1]; k=-1.000953; o=1:1:size(rx) i=1; rho1=0:17.7:d theta=0:10:360; rho=rho1; x(i)=rho.*cosd(theta)+(rx(o)*1000); y(i)=rho.*sind(theta)+(ry(o)*1000); xx(i)=(((x(i))-(rx(o)*1000))/d); yy(i)=(((y(i))-(ry(o)*1000))/d); l(i)=sqrt(x(i).^2+(y(i)).^2); c1=1/r1; s11(i)=c1*(l(i).^2); s12(i)=1+(sqrt(1-(1+k)*c1*c1*(l(i).^2))); s1(i)=s11(i)/s12(i); %hyperbola sag s2(i)=(r2(o)-sqrt((r2(o).^2)-(l(i).^2))); %best fit sag m(i)=abs((-s1(i)+s2(i))); i=i+1; end end dz=m'; xn=xx'; yn=yy'; z=[dz xn yn]; end
after each iteration of loop, arrays dz
, xn
, yn
, , matrix z
modified. how save output of every iteration?
you can use concept of multidimensional arrays follows:
clc; clear all; close all; format long; d=717; r1=60000; r2=[61043; 62000]; rx=[0; 10]; ry=[11.212; 1]; k=-1.000953; o=1:1:size(rx) i=1; rho1=0:17.7:d theta=0:10:360; rho=rho1; x(i)=rho.*cosd(theta)+(rx(o)*1000); y(i)=rho.*sind(theta)+(ry(o)*1000); xx(i)=(((x(i))-(rx(o)*1000))/d); yy(i)=(((y(i))-(ry(o)*1000))/d); l(i)=sqrt(x(i).^2+(y(i)).^2); c1=1/r1; s11(i)=c1*(l(i).^2); s12(i)=1+(sqrt(1-(1+k)*c1*c1*(l(i).^2))); s1(i)=s11(i)/s12(i); %hyperbola sag s2(i)=(r2(o)-sqrt((r2(o).^2)-(l(i).^2))); %best fit sag m(i)=abs((-s1(i)+s2(i))); i=i+1; end end dz(:,:,o)=m'; xn(:,:,o)=xx'; yn(:,:,o)=yy'; z(:,:,o)=[dz(:,:,o) xn(:,:,o) yn(:,:,o)]; end
Comments
Post a Comment