Why is my if function not working?

I do not know why my if function is giving me all my outputs, can someone help?
function [butterAmount]=howMuchButter(toastThickness, toastArea)
if (toastThickness < 0.5) && (toastArea<9);
butterAmount= 'smallAmnt';
elseif (toastThickness >= 0.5 && toastThickness <= 0.75) && (toastArea <= 16 && toastArea >= 9);
butterAmount='medAmnt';
elseif (toastThickness >0.75) && (toastArea >16);
butterAmount='largeAmnt';
else
butterAmount='tooWeird';
end
end

4 件のコメント

Walter Roberson
Walter Roberson 2018 年 2 月 10 日
What difficulty are you observing?
Heather Wun
Heather Wun 2018 年 2 月 10 日
I keep getting all four outputs in zyLab's MATLAB at the same time, yet in the MATLAB program when I input butterAmount(1,20) etc. it works.
Image Analyst
Image Analyst 2018 年 2 月 10 日
Attach the test code also to make it easy for us to run. What is "zyLab's MATLAB"? How is that different from the regular MATLAB that we run?
Walter Roberson
Walter Roberson 2018 年 2 月 10 日
You are running the function four times, each time asking that the output be assigned to a variable and that the results be displayed (because you do not have a semi-colon on the end of the line asking to not display output). Four outputs is the expected answer.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

タグ

質問済み:

2018 年 2 月 10 日

コメント済み:

2018 年 2 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by