From: Aui on
I would like to do if-else in 1 line in matlab but I don't know if MATLAB has this feature.

My C program is:

x = (d < D0)?20:30;

which is equal to
if (d < D0)
x = 20;
else
x = 30;

Please suggest how can I do this for 1 line in matlab??? Thank you very much.
From: Justus Skorps on
On 4 Dez., 06:15, "Aui " <littlebearproj...(a)gmail.com> wrote:
> I would like to do if-else in 1 line in matlab but I don't know if MATLAB has this feature.
>
> My C program is:
>
> x = (d < D0)?20:30;
>
> which is equal to
> if (d < D0)
> x = 20;
> else
> x = 30;
>
> Please suggest how can I do this for 1 line in matlab??? Thank you very much.

why does everyone wants to make his code unreadable?

if (d < D0) x = 20; else x = 30;end;

or for this special case

x = (d < D0)*10+20;