필터 지우기
필터 지우기

Deleting rows and columns of all zeroes in a symbolic matrix

조회 수: 2 (최근 30일)
Hello,
How can I delete all rows and columns of all zeroes in a symbolic matrix?
The solution listed here ( http://www.mathworks.com/matlabcentral/answers/40018-delete-zeros-rows-and-columns ) does not work when the matrix is symbolic. The any command produces an error "Unable to prove variable-name literally."
Thanks, Kevin

채택된 답변

Teja Muppirala
Teja Muppirala 2013년 2월 27일
syms x1
data = [ x1, 1, 0 ; 0, 0, 0 ; 0, 1, 0]
data( all( isAlways(data==0) ,2) ,:) = []
data( : ,all( isAlways(data==0) ,1)) = []

추가 답변 (1개)

Shashank Prasanna
Shashank Prasanna 2013년 2월 26일
The following worked perfectly fine for me. Can you share the exact error message you got?
x = [1 1 0;0 0 0;0 1 0]
>> data=sym(x)
data =
[ 1, 1, 0]
[ 0, 0, 0]
[ 0, 1, 0]
data( ~any(data,2), : ) = []; %rows
data( :, ~any(data,1) ) = []; %columns
  댓글 수: 1
Kevin Bachovchin
Kevin Bachovchin 2013년 2월 26일
The difference is that your data sym doesn't have any element syms.
Try
syms x1
data = [ x1, 1, 0 ; 0, 0, 0 ; 0, 1, 0]
data( ~any(data,2), : ) = []; %rows
data( :, ~any(data,1) ) = []; %columns
and you will get an error saying "Unable to prove 'x1' literally."

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

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by