need to remove [] in cell

조회 수: 2 (최근 30일)
Tomas
Tomas 2013년 11월 30일
댓글: dpb 2013년 12월 1일
I have once cell Z ={1x3 cell} [] {1x2 cell} [] {1x4 cell}
and then i have once cell Z = {1x7 cell} {1x5 cell} , Z{1}= [] [1x3 double] [] [1x3 double] [] [1x3 double] [1x3 double]
i find loop,if i have Z={1x3 cell} [] {1x2 cell} [] {1x4 cell} []; will be used Z(cellfun('isempty',Z))=[]; and then in 2 iteration is at the position Z{1}=[]; was be used: i=1:size(Z,2) Z{i}(cellfun(@isempty,Z{i})) = []; end
I want to write in one loop.
I have a dual results, I have once Z={1x3 cell} [] {1x2 cell} [] and once i have a results Z={1x3cell},in cell Z{1}=[] {1x2cell} I need to remove blanks place in cell i find one loop,in which I can use my cood
for example my cood
for i=size(Z,2)
if length(Z{i})==0
Z(cellfun('isempty',Z))=[];
Z
else
for i=1:size(Z,2) %
Z{i}(cellfun(@isempty,Z{i})) = [];
end
Z
end end
cod reports an error
??? Error using ==> cellfun Input #2 expected to be a cell array, was double instead.
Thanks.
  댓글 수: 1
dpb
dpb 2013년 12월 1일
I can't parse the actual request, sorry...perhaps give an example of what output you expect as well would help. Is it you're trying to simply process Z skipping over the empty cells or is it adequate to reduce Z by removing empty cells entirely?
As for the error,
Z{i}(cellfun(@isempty,Z{i})) = [];
??? Error using ==> cellfun Input #2 expected to be a cell array, was double instead.
The problem here is you dereferenced Z(i) by using the curlies {} so the result of Z{} is the array not the cell.

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

답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by