finding non-zero entries of a matrix

조회 수: 4(최근 30일)
Deepa Maheshvare
Deepa Maheshvare 2021년 2월 18일
댓글: dpb 2021년 2월 18일
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일
C=A|B;
  댓글 수: 2
dpb
dpb 2021년 2월 18일
+1
Had just come back to add, Matt... :)

댓글을 달려면 로그인하십시오.

추가 답변(0개)

범주

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by