没有在八度中绘制的线条

时间:2016-03-29 22:20:33

标签: octave

我被指示绘制一个圆圈,其中包含由矩阵变换的点。我似乎无法在所有点之间画一条线

c = cos(pi/8)
s = sin(pi/8)
A = [c -s; s c]
xy = [1;0]
axis('square')
for i = 1:17
  xy = A * xy;
  plot(xy(1, :), xy(2,:), 'r', 'linewidth', 2);
  hold on
endfor

当我运行代码时,我得到了这个

Result of running the code

如何在所有点之间绘制线条?

由于

1 个答案:

答案 0 :(得分:0)

您需要在绘制之前计算所有点。如果一次只绘制一个点,则无法将线连接到。

c = cos(pi/8)
s = sin(pi/8)
A = [c -s; s c]
xy = zeros(2,17);   %// preallocate the matrix
xy(:,1) = [1;0]
for i = 2:17
  xy(:,i) = A * xy(:,i-1);
endfor

plot(xy(1, :), xy(2,:), 'r', 'linewidth', 2);
axis('square')   %// goes *after* the plot (thanks @Andy)

Plot created by script