Question about making a 4-line if statement into a single line

17 ビュー (過去 30 日間)
Hakyoon Kim
Hakyoon Kim 2022 年 10 月 26 日
コメント済み: KALYAN ACHARJYA 2022 年 10 月 26 日
hello
first, here is my code
A=rand;
if A > 0.5
disp([num2str(A), ' ', 'Great indeed!'])
end
This is a code that generates a random number with 'rand' command and outputs 'Great indeed!' text if the value exceeds 0.5.
I want to make the code in single line but i have no idea.
Should I use 'switch' command or is there any better way?
  4 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2022 年 10 月 26 日
編集済み: KALYAN ACHARJYA 2022 年 10 月 26 日
@Hakyoon Kim The code is so simple, what is the objective behind to make it 1 line code?
Hakyoon Kim
Hakyoon Kim 2022 年 10 月 26 日
編集済み: Hakyoon Kim 2022 年 10 月 26 日
in fact, this is my college assignment.
my professor asked me to make this code to a single line.(no many lines, but only one line code)
but i have no idea to make it. haha

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

採用された回答

Matt J
Matt J 2022 年 10 月 26 日
if rand > 0.5, disp('Great indeed!') ; end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by