Plotting Piece-wise like function

3 ビュー (過去 30 日間)
Ferhat Bastug
Ferhat Bastug 2020 年 6 月 28 日
コメント済み: Aditya Verma 2020 年 6 月 28 日
Hey, I am new to MATLAB and to coding overall, so it should be an easy question answer, but still I am having some trouble. I have to plot agraph that is y=2x from 0 to 3 and y=2.5x from 3 to 4. (The graph I am adding is like what I am trying to plot). The thing is that I can not use commands like piece-wise because I'm using octave for MATLAB language. Thanks in advance.
  1 件のコメント
Aditya Verma
Aditya Verma 2020 年 6 月 28 日
The graph you have shown should be discontinuous at x=3

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

採用された回答

Aditya Verma
Aditya Verma 2020 年 6 月 28 日
You can use hold to plot multiple graphs in the same figure. This way you can graph any picewise function:
x1 = 0:3;
x2 = 3:4;
y1 = 2*x1;
y2 = 2.5*x2;
plot(x1, y1);
hold on
plot(x2, y2);
hold off
  2 件のコメント
Ferhat Bastug
Ferhat Bastug 2020 年 6 月 28 日
That works great, thanks for answering quick too!
Aditya Verma
Aditya Verma 2020 年 6 月 28 日
My pleasure! If this answer provides a good solution to your question, you can indicate it by accepting this answer.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by