简体   繁体   中英

Matlab - Multiply specific entries by a scalar in multidimensional matrix

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 xyz 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM