How to use invert values of a logical array

197 ビュー (過去 30 日間)
Dani Tormo
Dani Tormo 2014 年 3 月 11 日
回答済み: Sagar Damle 2014 年 3 月 11 日
Hello people,
the problem seems quite simple but I cannot figure out how to implement it.
I have two logical arrays. In one I have several values, and in the other the information about which of them I want to toggle. It is to apply a NOT gate, but I do not know how to implement it.
A = [1 1 1 1 1
0 1 0 1 0
1 1 1 1 1]
toggle = [0 0 0 0 0
1 1 1 1 1
0 0 0 0 0]
result = [1 1 1 1 1
1 0 1 0 1
1 1 1 1 1]
So in the end I want to toggle the middle row of A avoiding the use of if statements. How to do it?
Thanks!

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 3 月 11 日
A = [1 1 1 1 1
0 1 0 1 0
1 1 1 1 1]
toggle = logical([0 0 0 0 0
1 1 1 1 1
0 0 0 0 0])
% Apply not(), which is equivalent to ~
A(toggle) = ~A(toggle)
  1 件のコメント
Dani Tormo
Dani Tormo 2014 年 3 月 11 日
Thanks a lot Sean!

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

その他の回答 (1 件)

Sagar Damle
Sagar Damle 2014 年 3 月 11 日
xor(A,toggle)
OR
bitxor(A,toggle)
It is assumed that 'A' and 'toggle' contain only 0's and 1's.

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by