Hi all,I have a problem regarding deletion in cell array.
The cell array is like A=
neigh node_id
[] [1]
[3X1] [2]
[5X1] [3]
[2X1] [4]
[] [5]
[9X1] [6]
Now, i want to delete the cells A{1,:} and A{5,:},as (A{1,1}=[] and A{5,1}=[]). Thus resulting array would be like:
A=
neigh node_id
[3X1] [2]
[5X1] [3]
[2X1] [4]
[9X1] [6]
the code
A = A(~cellfun('isempty', A)); is not able to work on this type of array A=cell(6,2).
Thanks

댓글 수: 1

Jan
Jan 2015년 8월 3일
"is not able to work" is a bad description of the problem. Please post the error message or explain in detail the difference between the results and your expectations.

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

 채택된 답변

Jan
Jan 2015년 8월 3일

5 개 추천

A = A(~any(cellfun('isempty', A), 2), :);

댓글 수: 3

Aditya Shukla
Aditya Shukla 2015년 8월 4일
thanks, it works
One more solution I found is
B=[];
count=1;
for i=1:size(A,1)
if(size(A{i,1},2)~=0)
B{count,1}=A{i,1};
B{count,2}=A{i,2};
count=count+1;
end
end
Marcio Teixeira
Marcio Teixeira 2021년 4월 27일
That is clean and elegant solution Jan. I learn a lot with this community.
Thank you very much.

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

추가 답변 (1개)

Manolis Michailidis
Manolis Michailidis 2015년 8월 3일
편집: Manolis Michailidis 2015년 8월 3일

0 개 추천

have you tried something like this?
for i=1:length(your_cell_size)
idx(i) = find(~cellfun(@isempty,A{i}));
end
A=A{~idx}

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2015년 8월 3일

댓글:

2021년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by