When i plot a 2D plot and then try to label the axis only the label appears and the graph disappear

12 ビュー (過去 30 日間)
Hi everyone,
Im very new to matlab and im trying to learn from "getting started with matlab" . I have successfully plotted a 2-D sinusoid plot, but when i try to plot the axis, the graph disappears and the axis is plotted against a blank plot.
The same thing happens when i use ' hold on ' function. A blank plot appears after i use hold on.
x = linspace(0,2*pi);
y = sin(x);
plot(x,y)
hold on
y2 = cos(x);
plot(x,y2,":")
legend("sin","cos")
hold off
This is code im tring to use. Can anyone please explain what im doing wrong.

採用された回答

Gabriel Quattromani
Gabriel Quattromani 2022 年 5 月 30 日
Use 1 line to plot both graphs, as such:
x = linspace(0,2*pi);
y = sin(x);
y2 = cos(x);
plot(x,y,x,y2,":")
legend("sin","cos")
  2 件のコメント
Vivek Anand
Vivek Anand 2022 年 5 月 30 日
Thanks a lot Gabriel. It worked !!
Vivek Anand
Vivek Anand 2022 年 5 月 30 日
Just out of curiosity ,do you know why hold on function was not working for me?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by