check the index of cell which were removed

조회 수: 1 (최근 30일)
ha ha
ha ha 2018년 3월 6일
편집: Stephen23 2018년 3월 6일
Let's say:
A : 4x1 cell class
A={cell_1 ;cell_2 ; cell_3 ;cell_4 }
A={ [] ;[999,222];[444,222,2000]; [] };
B is index matrix of cell A:
B=[1;2;3;4] %index matrix of cell A
If I wanna remove the "empty cell" out of A, I can use this code:
A_remove=A(~cellfun('isempty',A));
And with respect to A, the index matrix B will be:
B_remove=[2;3]; %remove the index of "empty cell"
How can to find "B_remove" matrix from A &B ??

채택된 답변

Stephen23
Stephen23 2018년 3월 6일
편집: Stephen23 2018년 3월 6일
Using logical indices:
B_remove = cellfun('isempty',A)
B_keep = ~B_remove
If you really want the subscript indices then use find.
  댓글 수: 2
ha ha
ha ha 2018년 3월 6일
편집: ha ha 2018년 3월 6일
My question mean: " I want to find the index matric where the cell is not empty". If i use your code:
cellfun('isempty',A)
The result is: 4x1 logical. That is I don't want to see
I hope my index matrix will be : [2;3]=result
Stephen23
Stephen23 2018년 3월 6일
편집: Stephen23 2018년 3월 6일
As my answer told you:
find(~cellfun('isempty',A))
If you can use them then logical indices are more efficient.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by