MATLAB: How to delete empty cells in rows of a cell array

cell matrixdeletestrings

Hi,
I have a cell array of strings and empty cells. I would like to rearrange this so the empty cells are on the end of each row. For example:
[a] [b] [ ] [ ] [c]
[d] [ ] [e] [ ] [ ]
should become:
[a] [b] [c] [ ] [ ]
[d] [e] [ ] [ ] [ ]
The reason I want to do this is to ultimately end up with a cell matrix of strings in the following form:
[abc]
[de]
How would I accomplish these things, or is there a more efficient way to end up with the matrix of strings?

Best Answer

A={['a'] ['b'] [ ] [ ] ['c']
['d'] [ ] ['e'] [ ] [ ]}
idx=not(cellfun(@isempty,A))
out=arrayfun(@(x) cell2mat(A(x,idx(x,:))),[1:size(A,1)]','un',0)