How to plot cost curve with conditions

1 回表示 (過去 30 日間)
Muhammad Asad Hanif
Muhammad Asad Hanif 2016 年 7 月 26 日
I want to calculate total cost graphically and created the following script. I got result for y = 0 10 20 30 40 50 30 35 40 45 50, however my desired result is y = 0 10 20 30 40 50 55 60 65 70 75.
Kindly help me in my desired results. I do not know what I am missing.
x=0:1:10;
z1 = (x<=5).*x;
z2 = (x>5).*x;
y = 10*z1 + 5*z2
plot(x,y)

採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 7 月 26 日
編集済み: Andrei Bobrov 2016 年 7 月 26 日
y = cumsum((x <= 5 & x > 0)*10 + (x > 5)*5)
  1 件のコメント
Muhammad Asad Hanif
Muhammad Asad Hanif 2016 年 7 月 26 日
Thank you so much mate, It works perfectly

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by