0
votes

I have a cell array in MATLAB which looks like this,

arr=  4  5  8
     22 23  0

Zero values always appear at the end of the last row. If there are two zero values it will look like this,

arr=  4  5  8
     22  0  0

There is no row contains zeros for its all positions. Could anyone help me to remove those zero values exists in the last row? What I want is something like this

arr=  4   5   8
     22  23
1
Do you want [ ] in place of zeros? There has to be something. You can't have arr= {4 5 8; 22 23} - Sardar Usama
Not possible unless you have a place holder in each cell. MATLAB does not support ragged matrices. - rayryeng
@SardarUsama yup.. I want [ ] in those places. Since I have a lot of cell arrays like that, I want an efficient way. - Nipuna Dilhara

1 Answers

4
votes

If you have scalars at every index of the cell array then convert arr to a matrix, find the indices where zeros are present and then replace them with [].

arr([arr{:}]==0)={[]};