Suppose I have Matrix A:
A =
1 2 3
4 5 6
For every element x<2, add 10,
for every element x>5, add 20, and
for every element 2<=x<=5, add 30.
So for my example matrix A, I need to end up with the following matrix B:
B =
11 32 33
34 35 26
I need to be able to do this in a general way, since the actual matrix will be quite large. Any suggestions? Can I use the IF statement?
You don’t need an
IFyou need logical indexing: