storing script outputs as an array

조회 수: 9 (최근 30일)
Erik Anderson
Erik Anderson 2017년 3월 15일
댓글: Erik Anderson 2017년 3월 15일
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
Jan
Jan 2017년 3월 15일
What is your question?
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
  댓글 수: 1
Erik Anderson
Erik Anderson 2017년 3월 15일
ah, yes. Thank you very much for your help! Much appreciated

댓글을 달려면 로그인하십시오.

카테고리

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