finding non-zero entries of a matrix

1 次查看(过去 30 天)
Hi All,
I've 2 matrices, A and B.
A = [1 0 2; 3 4 5; 0 0 0];
B = [0 0 0; 1 0 0; 1 1 1];
I want to generate a matrix C which assigns 1 to non-zero entries in both A and B.
C = [1 0 1; 1 1 1; 1 1 1]
For just A , I could do
C = zeros(3)
C(find(A~=0)) = 1
I'd like to ask for suggestion on how to assign 1 for all non-zero entries in both A and B.

采纳的回答

dpb
dpb 2021-2-18
  2 个评论
Matt J
Matt J 2021-2-18
编辑:Matt J 2021-2-18
Or C=double(A|B) if you want the result in floating point.
dpb
dpb 2021-2-18
+1
Had just come back to add, Matt... :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by