need to remove [] in cell
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
dpb
am 1 Dez. 2013
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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!