-1

C is a 2 by 360 matrix that forms outline of a unit circle. C = [v1|v2|v3... v360] where v1 is e rotated by 1◦, v2 is e rotated by 2◦ etc. R is a given rotation matrix. e is a column vector [1 0]

I initialized the matrix by

>> C=zeros(2,360);

I don't know how use the for loop to populate the entries of matrix C

>> for c = 1:360
C = (R^c)*e;
end

And then the following is supposed to plot the circle.

>> plot(C(1,:), C(2,:))
4

1 回答 1

2

您需要在每次旋转时设置每一列,因此您需要在每次旋转时设置 C(:,c)。IE

for c = 1:360
    C(:,c) = (R^c) * c;
end

但是,您可以在没有 for 循环的情况下完成整个操作。(MATLAB 喜欢避免 for 循环)。

自从

t = 2*pi/360;
R = [cos(t) -sin(t); sin(t) cos(t)];

我们有

R*e = [cos(t); sin(t)];

所以我们正在寻找

C = [cos(t) cos(2*t) ... cos(360*t);
     sin(t) sin(2*t) ... sin(360*t)];

IE

C = [cos(t * (1:360)); sin(t * (1:360))];
于 2013-10-27T05:52:39.523 回答