plotting a special function

1 visualizzazione (ultimi 30 giorni)
Ali Roshanzamir
Ali Roshanzamir il 4 Ago 2020
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 Commenti
Ali Roshanzamir
Ali Roshanzamir il 4 Ago 2020
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 il 4 Ago 2020
Use logical indexing based upon logical comparisons you do between theta and the constants of the question.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 4 Ago 2020
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.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by