Prev: I have a code which doesnt work on the deploy mode, but works on the normal mode.
Next: Help in lsqr / fit
From: Stephan on 20 Apr 2010 14:22 Hi there, how can I delete cells (arrays of different length) with a size==1 in a cell array? example for an cell array C. Cells 3 and 6 have a size of 1x2 and have to be deleted: >>C(1:6) ans = [13x2 single] [14x2 single] [1x2 single] [9x2 single] [11x2 single] [1x2 single] I could manage it for empty cells using cellfun % Empty cells in cell arrray will be deleted. C(cellfun(@(C) isempty(C),C))=[]; Thanks Stephan
From: Walter Roberson on 20 Apr 2010 14:26 Stephan wrote: > Hi there, > > how can I delete cells (arrays of different length) with a size==1 in a > cell array? > > example for an cell array C. Cells 3 and 6 have a size of 1x2 and have > to be deleted: >>> C(1:6) > ans = [13x2 single] [14x2 single] [1x2 single] [9x2 > single] [11x2 single] [1x2 single] > I could manage it for empty cells using cellfun > % Empty cells in cell arrray will be deleted. > C(cellfun(@(C) isempty(C),C))=[]; C(cellfun(@(c) size(c,1) == 1, C)) = []; or C = C(cellfun(@(c) size(c,1) > 1, C)); Note: deleting entries takes about 4 times as long as the approach of copying the ones to be preserved.
From: Stephan on 20 Apr 2010 14:43 Thanks Walter, works pretty fine!
From: Bruno Luong on 20 Apr 2010 15:05 If speed is a concern, C(cellfun('size',C,1)==1) = []; is significantly faster than Walter's solution C(cellfun(@(c) size(c,1) == 1, C)) = []; Bruno
From: Walter Roberson on 20 Apr 2010 15:27 Bruno Luong wrote: > If speed is a concern, > > C(cellfun('size',C,1)==1) = []; > > is significantly faster than Walter's solution > > C(cellfun(@(c) size(c,1) == 1, C)) = []; That makes sense, Bruno, but hints that C(Cellfun(@size, C, 1)==1) = []; might be faster than with 'size' -- though you might need to be in a function to detect the difference.
|
Next
|
Last
Pages: 1 2 Prev: I have a code which doesnt work on the deploy mode, but works on the normal mode. Next: Help in lsqr / fit |