Logical Indexing Within a Symbolic Array

조회 수: 4 (최근 30일)
Kamal Premaratne
Kamal Premaratne 2020년 12월 30일
댓글: Ameer Hamza 2020년 12월 30일
Suppose I have a symbolic array like
A = [0 0 0 w7 0 0;
0 0 0 0 w9 0;
0 w3 0 0 0 0;
0 0 w5 0 0 0;
w1 0 w6 w8 0 0;
w2 w4 0 0 w10 0];
where w1, ..., w10 are symbolic real variables. I would like to generate a "binary" array which identifies where the symbolic variables w1, ..., w10 are located, meaning that the output should be
A_bin = [0 0 0 1 0 0;
0 0 0 0 1 0;
0 1 0 0 0 0;
0 0 1 0 0 0;
1 0 1 1 0 0;
1 1 0 0 1 0];
Is there a way MATLAB could generate A_bin from A?
Thank you.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 30일
Try this
syms w1 w2 w3 w4 w5 w6 w7 w8 w9 w10
A = [0 0 0 w7 0 0;
0 0 0 0 w9 0;
0 w3 0 0 0 0;
0 0 w5 0 0 0;
w1 0 w6 w8 0 0;
w2 w4 0 0 w10 0];
A_bin = ~isAlways(A==0)
or
A_bin = ~isnan(A./A)
  댓글 수: 2
Kamal Premaratne
Kamal Premaratne 2020년 12월 30일
Fantastic. Thank you so much.
Ameer Hamza
Ameer Hamza 2020년 12월 30일
I am glad to be of help!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 12월 30일
~isSymType(A, 'constant')
  댓글 수: 1
Kamal Premaratne
Kamal Premaratne 2020년 12월 30일
This also works. Thank you very much.

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

카테고리

Help CenterFile Exchange에서 Symbolic Variables, Expressions, Functions, and Preferences에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by