Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

delete zeros rows and columns

Asked by aboomnea on 1 Mar 2012

i try do delete rows and columns that are zeros but it cut also part of shape .I use this code

u=I;   
%%
old=[];
new=all(~u);
while ~isequal(old,new)
    u(new,:)=0;
    old=new;
    new=all(~u);
end
 u(new,:)=[];
 u(:,new)=[];
       av=u;
       av(~any(u,2),:)=[];
   %radious of puple
  figure, imshow(av,[]); 

so any other way to do that

0 Comments

aboomnea

3 Answers

Answer by Jonathan Sullivan on 2 Mar 2012
Accepted answer
u = I;
zc = ~any(u);
u(:,zc) = [];
zr = ~any(u,2);
u(zr,:) = [];

1 Comment

aboomnea on 2 Mar 2012

thank u "Jonathan Sullivan"

Jonathan Sullivan
Answer by Walter Roberson on 1 Mar 2012
u = I;
zc = ~any(u);
zr = ~any(u,2);
u(zc,zr) = [];
imshow(u, []);

1 Comment

aboomnea on 2 Mar 2012

i try this code but i get this error

Subscripted assignment dimension mismatch.

Error in first_step_to_final (line 110)
u(zc,zr) = [];

why? how to solve it

Walter Roberson
Answer by Andrea on 30 May 2012

data( all( ~any( data), 2 ), : ) = []; % removes all rows with all zero

data( :, all( ~any( data ), 1 ) ) = []; % and columns

0 Comments

Andrea

Contact us