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

조회 수: 10 (최근 30일)
N/A
N/A 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?
N/A
N/A 2022년 10월 26일
편집: N/A 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by