??? Index exceeds matrix dimensions. Error in ==> Untitled at 267 if length(W{i})==0;

{1x3 cell} {1x2 cell} {1x4 cell}
W{2}{1}={[1 2],[],[2 5 3]}
for i=1:size(W,2)
if length(W{i})==0;
W(cellfun('isempty',W))=[];%odstranenie prazdnych miest
else
%zmaze prazdne miesta v poli
W{i}(cellfun(@isempty,W{i})) = [];
end
end
W
I want to delete empty place in cell,2 events may occur once Z ={1x3 cell} [] {1x2 cell} [] {1x4 cell} or can be Z{1}= [1x3 double] [1x3 double] [1x3 double] [] []
Thanks.

답변 (1개)

Try this
idx=cellfun(@isempty,W{2}{1});
W{2}{1}(idx)=[]

댓글 수: 5

it does not work
i have code
for i=1:size(W,2)
for j=length(W{i})
if j~=0
W{i}(cellfun(@isempty,W{i})) = [];
else
W(cellfun('isempty',W))=[];%odstranenie prazdnych miest
end
end
end
W
??? Index exceeds matrix dimensions.
Error in ==> Untitled at 259 for j=length(W{i})
i want if treated W(cellfun('isempty',W))=[]; that all completed. what do i use,so I ended the loop
If you post an example, it will be useful
i have cell
The first iteration will Z={1x5cell} {1x4cell} in cell Z{1}=[] [1x3 double] [1x3 double] [1x3 double] ] [] Z{2}=[] [] [1x3 double] [1x3 double]
I will use for i=1:size(Z,2)
Z{i}(cellfun(@isempty,Z{i})) = [];
The second iteration Z= [] {1x4cell} i will use Z(cellfun('isempty',Z))=[]
I want to write in one loop i.
I need to remove empty space automatically.
I will give an example
W{1}{1}={[] 1:3 3:5 1:3 [] }
W{2}{1}={[] [] 1:3 1:3 }
idx=cellfun(@isempty,W{2}{1});W{2}{1}(idx)=[]
celldisp(W{2})
i need when i have Z=[] {1x3 cell} {1x2 cell} i want to delete [] if length(Z(1))==0 error message
? Undefined function or method 'eq' for input arguments of type 'cell'.

이 질문은 마감되었습니다.

태그

질문:

2013년 12월 1일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by