MATLAB Answers

0

Deleting rows and columns of all zeroes in a symbolic matrix

Asked by Kevin Bachovchin on 26 Feb 2013

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

  0 Comments

Products

No products are associated with this question.

2 Answers

Answer by Teja Muppirala
on 27 Feb 2013
 Accepted answer
syms x1
data = [ x1, 1, 0 ; 0, 0, 0 ; 0, 1, 0]
data( all( isAlways(data==0) ,2) ,:) = []
data( : ,all( isAlways(data==0) ,1)) = []

  0 Comments


Answer by Shashank Prasanna
on 26 Feb 2013

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 Comment

Kevin Bachovchin on 26 Feb 2013

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."


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!