Question about making a 4-line if statement into a single line
Show older comments
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 Comments
A=rand;
if A > 0.5
fprintf('%f Great indeed\n',A)
end
I think a conditional statement is required. If the issue is that the code must lie on one line, then do
A=rand; if A > 0.5, fprintf('%f Great indeed\n',A), end
KALYAN ACHARJYA
on 26 Oct 2022
Edited: KALYAN ACHARJYA
on 26 Oct 2022
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!