storing script outputs as an array

8 views (last 30 days)
Erik Anderson
Erik Anderson on 15 Mar 2017
Commented: Erik Anderson on 15 Mar 2017
I wanted to try identifying convex polygons by their projected widths. How can I get the outputs, D, stored in a compact array that I can save and work with?
%loop that will have 1440 iterations (each iteration
%representing a rotation of the plane by 0.5 degrees)
for t= 1:2000
format('long')
%imagine points in 2-dimensional euclidean space. These three vectors
%represent the three vertices of an equilateral triangle cetered at the
%origin
A=[0;1];
B=[-0.86603; -0.50000];
C=[0.86603; 0.50000];
%T is designed to be a 0.5 degree counter-clockwise rotation matrix, sending each
%of the previous vectors to their 0.5 degree rotated counterparts
T= [ 0.99996 -0.00873;0.00873 0.99996];
%P extracts the x values of each vector above, discarding the rest
P= [1 0];
%represent the rotated images of A,B,C, for some iteration 't'
tA=(T^t)*A;
tB=(T^t)*B;
tC=(T^t)*C;
%represent the projection of tA,tB,tC onto the x-axis.
imA=P*tA;
imB=P*tB;
imC=P*tC;
%distances between the respective projections
distAB=abs(imA-imB);
distBC=abs(imB-imC);
distCA=abs(imC-imA);
%making a vector V with elements 'distAB' 'distBC' 'distCA'
X=[1 0 0];
Y=[0 1 0];
Z=[0 0 1];
dX=distAB*X;
dY=distBC*Y;
dZ=distCA*Z;
V= dX+dY+dZ;
% D = max element in V is the width of the 'shadow' of the triangle on the
%x-axis
D=max(V)
end
  2 Comments
Jan
Jan on 15 Mar 2017
What is your question?
Erik Anderson
Erik Anderson on 15 Mar 2017
my question is
"How can I get the outputs, D, stored in a compact array that I can save and work with?"
right now I am using
Output=zeros(1,10000); Output(t)=D; xlswrite('triangleout.xls',Output);
seems to work well

Sign in to comment.

Answers (1)

per isakson
per isakson on 15 Mar 2017
Edited: per isakson on 15 Mar 2017
I guess: this is what you try to do.
D = nan( 1, 2000 );
format('long')
%imagine points in 2-dimensional euclidean space. These three vectors
%represent the three vertices of an equilateral triangle cetered at the
%origin
A=[0;1];
B=[-0.86603; -0.50000];
C=[0.86603; 0.50000];
%T is designed to be a 0.5 degree counter-clockwise rotation matrix, sending each
%of the previous vectors to their 0.5 degree rotated counterparts
T= [ 0.99996 -0.00873;0.00873 0.99996];
%P extracts the x values of each vector above, discarding the rest
P= [1 0];
for t= 1:2000
%represent the rotated images of A,B,C, for some iteration 't'
tA=(T^t)*A;
tB=(T^t)*B;
tC=(T^t)*C;
%
%represent the projection of tA,tB,tC onto the x-axis.
imA=P*tA;
imB=P*tB;
imC=P*tC;
%
%distances between the respective projections
distAB=abs(imA-imB);
distBC=abs(imB-imC);
distCA=abs(imC-imA);
%
%making a vector V with elements 'distAB' 'distBC' 'distCA'
X=[1 0 0];
Y=[0 1 0];
Z=[0 0 1];
%
dX=distAB*X;
dY=distBC*Y;
dZ=distCA*Z;
V= dX+dY+dZ;
%
% D = max element in V is the width of the 'shadow' of the triangle on the
%x-axis
D(t)=max(V);
end
especially note
D = nan( 1, 2000 );
...
D(t) = max(V);
in the original code D was overwritten two thousand times
  1 Comment
Erik Anderson
Erik Anderson on 15 Mar 2017
ah, yes. Thank you very much for your help! Much appreciated

Sign in to comment.

Categories

Find more on Computational Geometry in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!