フィルターのクリア

multiplication of certain values using logical array

19 ビュー (過去 30 日間)
Rachel
Rachel 2012 年 2 月 2 日
編集済み: Jon 2013 年 9 月 26 日
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,
Rachel

採用された回答

Amit Davidi
Amit Davidi 2012 年 2 月 2 日
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?...)
  1 件のコメント
Rachel
Rachel 2012 年 2 月 2 日
thanks, I knew there was a simple way somehow!

サインインしてコメントする。

その他の回答 (2 件)

Rachel
Rachel 2012 年 2 月 2 日
but this changes every value? (andrei) - I need to change just the values which are true in the logical.e.g.
A = 1,2,3;4,5,6;7,8,9 % original matrix
logical = 1,0,0;0,1,1;1,1,0 % logical array
B = -1,2,3;4,-5,-6;-7,-8,9 % A where the values sharing the same position of logical true have been multiplied by -1.
thanks
Rachel

Amit Davidi
Amit Davidi 2012 年 2 月 2 日
Of course, it'll change only the values where the logical array is true. Note, however, that the command
B = -A(fltr);
would not give you what you want! This will result in a column vector of the changed values.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by