storing script outputs as an array

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 Kommentare

Jan
Jan am 15 Mär. 2017
What is your question?
Erik Anderson
Erik Anderson am 15 Mär. 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

per isakson
per isakson am 15 Mär. 2017
Bearbeitet: per isakson am 15 Mär. 2017

0 Stimmen

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 Kommentar

Erik Anderson
Erik Anderson am 15 Mär. 2017
ah, yes. Thank you very much for your help! Much appreciated

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Computational Geometry finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 15 Mär. 2017

Kommentiert:

am 15 Mär. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by