how to remove empty cell array contents?

1.710 views (last 30 days)
Hello, I've got a cell array, lets say:
R =
[ 691x2 double]
[ 12x2 double]
[ 11x2 double]
[ 112x2 double]
[ 13x2 double]
Does anyone know of a quick way I could remove the non-zero elements of the cell array? This cell array will be a different length and will have a different number of non-zero elements each time, dependent on another loop
Thanks, Jim

Accepted Answer

Aurelien Queffurust
Aurelien Queffurust on 25 Jan 2012
To remove empty cell array contents (title of your question) :
Jan on 9 May 2017
@Chintan Modi: Use the flags to catch the attraction to inapropriate messages, not for posting data concerning your problem.
Please do not attach a new question as a comment to an existing answer. Open a new thread instead.
There is no picture. What is the type of your variable sf? size(sf(3,:),2) replies the size of the array and does not care about the contents of the cell elements.
If you want to count the non-empty cells, use:
sum(~cellfun('isempty', sf(3, :))

Sign in to comment.

More Answers (1)

David Young
David Young on 25 Jan 2012
Rnew = R(~cellfun(@isempty, R))
Daniel Bridges
Daniel Bridges on 1 Mar 2017
>> data(~structfun(@isempty,data))
Error using structfun
Inputs to STRUCTFUN must be scalar structures.

Sign in to comment.


Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by