plotting a special function
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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.
I recommend that you read https://www.mathworks.com/matlabcentral/answers/534868-make-matrix-with-loop#answer_439778
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!