フィルターのクリア

Using "if" and "disp" in a comparison of two numbers

3 ビュー (過去 30 日間)
Sergio
Sergio 2024 年 1 月 18 日
コメント済み: Sergio 2024 年 1 月 18 日
I made the code to compare two numbers, however it stops after input of the numbers, instead of doing the comparison. I have a big MATLAB manual here, and I also look online, but can't find any reference to this type of operation. Any hints?
Thanks
a=input("Give a value for a")
b=input("Give a value for b")
if a == b
disp("equal")
if a > b
disp("a is greater than b")
if a < b;
disp("a is smaller than b")
end

採用された回答

Dyuman Joshi
Dyuman Joshi 2024 年 1 月 18 日
You need to use the elseif condition.
Refer to the documentation for more info - if, elseif, else
a=5;%input("Give a value for a")
b=6;%input("Give a value for b")
if a == b
disp("equal")
elseif a > b
disp("a is greater than b")
elseif a < b;
disp("a is smaller than b")
end
a is smaller than b
  1 件のコメント
Sergio
Sergio 2024 年 1 月 18 日
Thanks Dyuman, I will note this down.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by