# Basic Explanation of ‘If-Else’ In MatLab Programming(Illustrated Expression)

Matlab programming is very useful tool for engineers or mathematicians to calculate or solve very complex mathematical problems. In this programming language, you can use the general coding charactheristics such as ‘if-else’.  In this article we will explain how to use ‘if-else’ in Matlab.

### How To Use ‘If-Else’ In MatLab Programming?

Example for the use of if-else in Matlab.

We want to explain the if-else in Matlab with a very basic example as above. If you want mucg more complex examples and explanations about if-else in Matlab, inform as about it at comments below.

We have created a ‘for’ loop and a vector as shown by red arrow. In each step of this for loop in Matlab, the elements of this vector will be assesed by if-else codes inside the ‘for’ loop. On every loop ‘a’ will have different values. According to these values, a will be displayed according to it’s sitauation.

In the first ‘if’  code, ‘a’ will be displayed if it is bigger than 10 as shown by green arrow above. So we typed a ‘condition’ as a>10 near of ‘if’.

Take a look at the ‘elseif’, we put the condition of ‘a<0’ and ‘a’ will be displayed if the condition is valid for the value of ‘a’ in current loop.

‘Else’ means, the other conditions except for above conditions in ‘if’ and ‘elseif’. For this example, else meand the number of ‘a’ is between 0 and 10.

As you can see at the orange box above, the all the numbers in the loop vector are displayed according to their condition inside the ‘if-else’ code in Matlab.

So the logic of ‘if-else’ is like that in Matlab programming.