storing script outputs as an array

9 次查看(过去 30 天)
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 个评论
Erik Anderson
Erik Anderson 2017-3-15
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

请先登录,再进行评论。

回答(1 个)

per isakson
per isakson 2017-3-15
编辑:per isakson 2017-3-15
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

类别

Help CenterFile Exchange 中查找有关 Computational Geometry 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by