plotting a special function

조회 수: 1 (최근 30일)
Ali Roshanzamir
Ali Roshanzamir 2020년 8월 4일
댓글: 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.
  댓글 수: 1
Ali Roshanzamir
Ali Roshanzamir 2020년 8월 4일
Ok, Thanks for your information

댓글을 달려면 로그인하십시오.

카테고리

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