MATLAB: Multiplication of certain values using logical array


Hi all,
I have a matrix from which I have derived a logical array. What I'd like to do is multiply true values in the original matrix by -1. I can change these values to a constant value but I can't figure out how to multiply the existing value.
I should add that I'm after a vectorisation rather than loops to quicken my script.
thanks in advance,

Best Answer

If A is your original matrix and fltr is the derived logical array (having the same dimensions as A), than:
A(fltr) = -A(fltr);
Should do the trick.
(I think Andrei might have misunderstood your question. Or did I?...)