Conditional Statements for specific elements in Arrays and Matrixes
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:
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
The output is P = 25 which is correct for the one element.
But using this method, I have to write out four if-then-else 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 If-Then-Else statement 240 times?