Matlab - Multiply specific entries by a scalar in multidimensional matrix

95 views Asked by At

I'm having problems multiplying specific values within my multidimensional matrix by a scalar. My matrix has the following dimension:

size(comDatabe) = 5   10   3   397   10

The third dimension is an x-y-z coordinate frame. Something went wrong and now my y-axis is defined upside down for one subject (#8 out of 10 from the last dimension, positive values are negative and vice versa). I want to fix this by multiplying all these y values by -1. I tried to do these things but that didn't work:

comDatabe(:,:,2,:,8) = comDatabe(:,:,-2,:,8)
comDatabe(:,:,[1 2 3],:,8) = comDatabe(:,:,[1 -1*2 3],:,8)

How do I multiply this specific "column" by -1 in my multidimensional matrix?

1

There are 1 answers

2
Maksim Khaitovich On BEST ANSWER

Errr, why you multiply indexes instead of values?

I tried this: comDatabe(:,:,[1 2 3],:,8) = comDatabe(:,:,[1 2 3],:,8)*-1

And it worked.