Undefined function or variable 'cosump'. Error in calc (line 3). what am I doing wrong?

function cost=calc(consump)
if consump<=160
cost= cosump*33;
elseif (consump>161) && (consump<=300)
cost= 160*33+(consump-160)*72;
end
end

 採用された回答

Star Strider
Star Strider 2018 年 1 月 2 日
You have a repeated typographical error, typing ‘cosump’ instead of ‘consump’.
See if this corrected version of your function works:
function cost = calc(consump)
if consump<=160
cost = consump*33;
elseif (consump>161) && (consump<=300)
cost= 160*33+(consump-160)*72;
end
end

2 件のコメント

Muath Zahran
Muath Zahran 2018 年 1 月 2 日
Thank you.
Star Strider
Star Strider 2018 年 1 月 2 日
My pleasure.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 1 月 2 日
You're probably typing F5 or hitting the green run triangle to run the code. Doing this does not pass in any value for consump. You would need to have a line of code, either in the command window or an m-file, where you pass in a value. For example, for 50:
cost = calc(50);

カテゴリ

タグ

質問済み:

2018 年 1 月 2 日

編集済み:

2021 年 5 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by