


For the outmost for-end loop, we created a vector variable ‘y’, which will index the row of individual element from ‘x’ to assing it to matrix ‘D’ as column. We created a for-end loops that intertwined to each other. So in each loop, we need to index the matrix elements individually to assign these valus to a new matrix elements. In here, we want to convert a 3×4 matrix which is ‘x’ into a 4×3 matrix which is ‘D’ above. This example is about the priority of the for-end loops that coded inside themselves. You can obtain programmes for these new values in each loop, inside the for-end command in Matlab.Īnother example about for-end loop in Matlab x = So in each loop, the variable that assigned to for-end command will take a new values. As you see in the result at command window, 3 of elements has no imaginary section, so they are real, and the number that has imaginary section is 5. If there is no imaginary section(so it is ‘else’ in our code), the value of ‘real’ will be increased 1.Īt the end of the loop, we want to see the values of these two vectors. If the imaginary section is not zero that we stated in if command above, the value of ‘im’ will be increased 1(im=im+1).

We asked this question with if-else in Matlab by indexing the each element of vector ‘x’ in each loop, inside ‘imag()’ command.
