回 帖 发 新 帖 刷新版面

主题:菜鸟求助

一个简单的循环
for n=1:10

       x(n)=sin(n*pi/10);

    end

       x

结果应为x =

  Columns 1 through 10 

    0.3090    0.5878    0.8090    0.9511    1.0000    0.9511    0.8090    0.5878    0.3090    0.0000

 而运算结果为x =

  Columns 1 through 10 

    0.3090    0.5878    0.8090    0.9511    1.0000    0.9511    0.8090    0.5878    0.3090    0.0000

  Columns 11 through 20 

   -3.5510   -3.3061   -3.0612   -2.8163   -2.5714   -2.3265   -2.0816   -1.8367   -1.5918   -1.3469

  Columns 21 through 30 

   -1.1020   -0.8571   -0.6122   -0.3673   -0.1224    0.1224    0.3673    0.6122    0.8571    1.1020

  Columns 31 through 40 

    1.3469    1.5918    1.8367    2.0816    2.3265    2.5714    2.8163    3.0612    3.3061    3.5510

  Columns 41 through 50 

    3.7959    4.0408    4.2857    4.5306    4.7755    5.0204    5.2653    5.5102    5.7551    6.0000
不知问题出在哪里,请大虾指教,谢了

回复列表 (共3个回复)

沙发

>> for n=1:10

       x(n)=sin(n*pi/10);

    end

       x

x =

  Columns 1 through 8

    0.3090    0.5878    0.8090    0.9511    1.0000    0.9511    0.8090    0.5878

  Columns 9 through 10

    0.3090    0.0000
没问题呀,我拿你的直接运行的结果
是不是你在前面做过其他的运算,n的有其他程序运行
用clear先把内存清了

板凳

n=1:10;
y=sin(n*pi/10);
plot(n, y, 'r');

3 楼

正如1楼所说,谢了!

我来回复

您尚未登录,请登录后再回复。点此登录或注册