Wondering how to use the min/max function in an array?

3 ビュー (過去 30 日間)
Sydney Frazier
Sydney Frazier 2020 年 9 月 1 日
コメント済み: Sydney Frazier 2020 年 9 月 1 日
a = input('What is a?','s');
b = input('What is b?','s');
c = input('What is c?','s');
d = input('What is d?','s');
Lengths = [ a b c d ];
S = min(Lengths)
L = max(Lengths)
PQ = sum(Lengths) - (S + L)
if S + L < PQ
Condition = 'Grashof'
elseif S + L == PQ
Condition = 'Special Grashof'
elseif S + L > PQ
Condition = 'Non-Grashof'
end
Whenever I input this, for a=7, b=11, c=8, and d=9, it gives me that S=49 and L=57. I want S=7 and L=11

採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 1 日
You are using the 's' option for input(). That means that you want characters back instead of numbers. 49 corresponds to the character '7'
  1 件のコメント
Sydney Frazier
Sydney Frazier 2020 年 9 月 1 日
THANK YOU. This fixed the problem. I appreciate the help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by