How to make decision with Matlab programming language | applied electronics engineering

Latest

How to make decision with Matlab programming language

By Applied Electronics - Friday, March 17, 2017 No Comments
Matlab programming language supports decision making and iteration making elements like any other programming languages. In Matlab the decision making capability of a program is made available using the if statement and it's variants- if else, elseif, nested if etc.

Suppose that you allow users to enter some number using the input statement and you store the variable in say x.

x = input('Enter some number: ');

Now you want to perform some operation on x such that it requires real number. If is infiniy or is not real then you want to display to the user that the input is a Invalid Input. Such decision can be made using if elseif statement in Matlab.

if isinf(x) || ˜isreal(x)
disp(’Invalid Input!’)
y = NaN;
elseif (x == round(x)) && (x > 0)
y = prod(1:x-1)
else
y = gamma(x)
end

See how if statement in Matlab programming language is similar or different with other programming languages- comparison if statement in C, Matlab and Python programming languages for more.

Tags:

No Comment to " How to make decision with Matlab programming language "