【问题标题】:Use a for loop in Matlab with increments of 15在 Matlab 中使用 for 循环,增量为 15
【发布时间】:2014-10-14 18:42:34
【问题描述】:

我是 matlab 新手,我必须使用增量为 15 的 for 循环作为坐标点。

我试过了

for theta = 0; and(theta <= 360, theta >= 0)
theta +15;
end

theta = 0;
   for theta = [0:360];
       theta = theta+15;
   end

第二个是我让它工作的关闭,但它仍然超过 360,第一个似乎更有意义,但它给了我一个错误,说 theta 以前被用作变量。

y12 = sind(theta) + cosd(theta);
y1 = sind(theta);
y2=cosd(theta);
plot(theta,y12)
plot(theta,y1)
plot(theta,y2)
title 'Project 7D - 3 curves(0-2*pi)'
xlabel 'Angle in Radian'
ylabel 'Function Value'

【问题讨论】:

    标签: matlab loops for-loop increment


    【解决方案1】:

    这实际上不需要循环。

    theta=0:15:360;
    
    y12 = sind(theta) + cosd(theta);
    y1 = sind(theta);
    y2 = cosd(theta);
    
    hold all;
    plot(theta,y12)
    plot(theta,y1)
    plot(theta,y2)
    title 'Project 7D - 3 curves(0-2*pi)'
    xlabel 'Angle in Radian'
    ylabel 'Function Value'
    

    【讨论】:

      【解决方案2】:
          for theta=0:15:360
           y12 = sind(theta) + cosd(theta);
           y1 = sind(theta);
           y2=cosd(theta);
           hold all;
           plot(theta,y12)
           plot(theta,y1)
           plot(theta,y2)
           title 'Project 7D - 3 curves(0-2*pi)'
           xlabel 'Angle in Radian'
           ylabel 'Function Value'
          end
      

      0:15:360 从 0 开始,每次递增 15,到 360 结束

      【讨论】:

      • 当我将其插入绘图时,它仅使用 360 作为值。
      • 我在正文中添加了它
      猜你喜欢
      • 2016-05-02
      • 1970-01-01
      • 2016-01-29
      • 2012-01-18
      • 1970-01-01
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      相关资源
      最近更新 更多