Why wont the lines on my plot show up
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!