Prev: I have a code which doesnt work on the deploy mode, but works on the normal mode.
Next: Help in lsqr / fit
From: Matt Fig on 20 Apr 2010 15:53 Walter Roberson <roberson(a)hushmail.com> wrote in message <hqkv7o$cpm$1(a)canopus.cc.umanitoba.ca>... > 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. This is not equivalent to Bruno's solution. This is, and will most certainly be slower: cellfun(@(x) size(x,1),C) It is my experience, at least with 2007b, that calling cellfun with the built-in strings is much faster than using function handles or anonymous functions. Also, Bruno's proposal will fail to remove column vectors, which satisfy the requirements (I think?) stated by the OP.
From: Bruno Luong on 20 Apr 2010 16:11 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <hql0n0$hqk$1(a)fred.mathworks.com>... > > > Also, Bruno's proposal will fail to remove column vectors, which satisfy the requirements (I think?) stated by the OP. It is not clear to me either Matt what cell elements have to be removed: If all vectors must be removed, then C(cellfun('size',C,1)==1 | cellfun('size',C,2)==1) = []; should do. Bruno
From: Bruno Luong on 20 Apr 2010 16:32 Walter Roberson <roberson(a)hushmail.com> wrote in message <hqkv7o$cpm$1(a)canopus.cc.umanitoba.ca>... > but hints that > > C(Cellfun(@size, C, 1)==1) = []; > > might be faster than with 'size' -- You are right Walter, this command throw out right away an syntax error, so it's certainly faster. ;-) More seriously, here is some timings: >> clear c >> c(1:1e6)={rand(12,2)}; >> tic; b=cellfun(@(c) size(c,1) == 1,c); toc Elapsed time is 5.330068 seconds. >> tic; b=cellfun('size',c,1)==1; toc Elapsed time is 0.019914 seconds. We have discussed about this topic not long ago. A limited number of string function handles are specifically implemented in the fast way under the hood within cellfun. Bruno
From: Matt Fig on 20 Apr 2010 16:46 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message > > We have discussed about this topic not long ago. A limited number of string function handles are specifically implemented in the fast way under the hood within cellfun. Too bad too... I wish TMW would add more of these ;-). And add some built-ins to BSXFUN, ACCUMARRAY, etc,.....
First
|
Prev
|
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 |