plotting a special function

1 次查看(过去 30 天)
Ali Roshanzamir
Ali Roshanzamir 2020-8-4
Hey guys,
I want to plot this curve. Please help me. It's too important for me!
N=45;
N(θ)= N*7/8 for 0<θ<π/4 & π<θ<5π/4
-N/8 for other θ
  3 个评论
Ali Roshanzamir
Ali Roshanzamir 2020-8-4
I did this but it doesn't show anything
N=45;
for teta=0:2*pi,
if((teta>pi/4)&(pi<teta<=5*pi/4)),
Nteta=7*N/8;
else
Nteta=-N/8;
end;
end;
subplot(2,1,1)
plot(teta,Nteta)
Walter Roberson
Walter Roberson 2020-8-4
Use logical indexing based upon logical comparisons you do between theta and the constants of the question.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2020-8-4
if((teta>pi/4)&(pi<teta<=5*pi/4)),
Nteta=7*N/8;
You are overwriting all of Nteta there, with a scalar. At the end of your for loop, Nteta will be a scalar that has whatever value was last assigned to it.
plot(teta,Nteta)
After the for teta loop, the loop control variable (teta) will have the value it was assigned last in the loop. So it will be the scalar 6. Then you are plotting that scalar on the x axis and the scalar Nteta on the y axis -- a single point. However, when you plot a single point without indicating a marker, then plot tries to draw just the between the single point and itself, which is not going to produce any visible marking.
for teta=0:2*pi,
Remember that the default increment for the : operator is 1, so you are asking to run the loop with teta = 0, 1, 2, 3, 4, 5, and 6.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by