how to remove empty cell array contents?

조회 수: 1,030 (최근 30일)
Jim O'Doherty
Jim O'Doherty 2012년 1월 25일
댓글: Jan 2017년 5월 9일
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

채택된 답변

Aurelien Queffurust
Aurelien Queffurust 2012년 1월 25일
To remove empty cell array contents (title of your question) :
R(~cellfun('isempty',R))
  댓글 수: 12
Chintan Modi
Chintan Modi 2017년 5월 9일
편집: Chintan Modi 2017년 5월 9일
I am also suffering from this problem. I want to delete the empty cells from this "sf" variable (i.e. shown in picture). I wish to delete it from variable so that whenever I try to find column size of the particular row; i'll be able to get only the matrix of that number cell and don't want to count the empty cell. for e.g. if i write
size(sf(3,:),2)
ans i want i.e. 5
but here it shows the 31
can someone help me to solve this problem?
Jan
Jan 2017년 5월 9일
@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, :))

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

David Young
David Young 2012년 1월 25일
Rnew = R(~cellfun(@isempty, R))
  댓글 수: 3
Andrei Bobrov
Andrei Bobrov 2012년 4월 25일
D1 = D.';
out = reshape(D1(~cellfun(@isempty,D1)),2,[])';
Daniel Bridges
Daniel Bridges 2017년 3월 1일
>> data(~structfun(@isempty,data))
Error using structfun
Inputs to STRUCTFUN must be scalar structures.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by