
This post has NOT been accepted by the mailing list yet.
This post was updated on .
I'm trying to figure out how to manipulate conditional statements for specific elements in a vector or matrix.
For example, suppose I have a 2x2 matrix M=[2, 9; 5, 1].
I want to test whether each element is greater than four
This won't work:
if (M<=4)
P=4
else
P=5*M
endif
That won't work because this results in every element of the Matrix being multiplied by 5
or M=[10,45; 25, 5] where I want M=[4,45; 25, 4]
Thus, I could write
if (M(2,1)<=4)
P=4
else
P=5*M(2,1)
endif
The output is P = 25 which is correct for the one element.
But using this method, I have to write out four ifthenelse statements to test each element. For the project I am working with, I potentially have a 6x40 matrix. How would I test each element without having to write out the IfThenElse statement 240 times?
