Why wont the lines on my plot show up

1 回表示 (過去 30 日間)
Sameeha Meher
Sameeha Meher 2021 年 3 月 4 日
回答済み: Cris LaPierre 2021 年 3 月 4 日
function phaseLine(f, ymin, ymax)
y0=[ymin:0.1:ymax];
a=y0(y0==0);
a=unique(a);
b=y0(y0~=0);
n=length(a)+length(b);
figure
if b>0
t=linspace(-1,1,n);
plot (t,b,'-b')
else if b<0
t=linspace(-1,1,n);
plot (t,b,'-r')
else
t=linspace(-1,1,n);
plot (t,a,'-k')
end
end
it doesnt work if i write linspace before the figure either

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 3 月 4 日
I think the issue is that you are using a vector in the conditional statement of your if statement. An if statement expects a single logical result. Your vector likely contains some values that are true for each condition and some that are false. Since they are not all true, only the else statement runs.
For your else case, you plot t and a. The issue here is that a is a single value, 0 (assuming your range allows for this). Since t is a vector, it will create a new series for each combination of t with a. Since there is only a single data point in each series, no line appears. Because you did not specify a marker in your lineSpec, nothing appears.
Perhaps you meant to do something like this.
y0=-5:0.1:5;
t=linspace(-1,1,length(y0));
figure
plot (t(y0>0),y0(y0>0),'-b')
hold on
plot (t(y0<0),y0(y0<0),'-r')
plot (t(y0==0),y0(y0==0),'-^k')
hold off

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by