From: Sean on 16 Jul 2010 16:13 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <i1qe3f$ouh$1(a)fred.mathworks.com>... > Almost the same solution, but for large size: > > a=ceil(4000*rand(1e5,5)); > > full(sum( sparse(mod((0:numel(a)-1)',size(a,1))+1, a(:), 1) > 0,1)) > > % Bruno That wins: %Elapsed time is 0.199475 seconds.
From: us on 16 Jul 2010 17:05 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <i1qe3f$ouh$1(a)fred.mathworks.com>... > Almost the same solution, but for large size: > > a=ceil(4000*rand(1e5,5)); > > full(sum( sparse(mod((0:numel(a)-1)',size(a,1))+1, a(:), 1) > 0,1)) > > % Bruno but with a lot of unnecessary data... a=[ceil(10*rand(1e5,5))+100000;ceil(10*rand(1e5,5))+200000]; r=full(sum( sparse(mod((0:numel(a)-1)',size(a,1))+1,a(:),1)>0,1)); whos r; %{ Name Size Bytes Class Attributes r 1x200010 1600080 double %} % while au=unique(a); size(au) % ans = 20 1 just a pedestrian thought... us
From: Bruno Luong on 16 Jul 2010 17:33 "us " <us(a)neurol.unizh.ch> wrote in message <i1qhi5$2jl$1(a)fred.mathworks.com>... > "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <i1qe3f$ouh$1(a)fred.mathworks.com>... > > Almost the same solution, but for large size: > > > > a=ceil(4000*rand(1e5,5)); > > > > full(sum( sparse(mod((0:numel(a)-1)',size(a,1))+1, a(:), 1) > 0,1)) > > > > % Bruno > > but with a lot of unnecessary data... > > a=[ceil(10*rand(1e5,5))+100000;ceil(10*rand(1e5,5))+200000]; > r=full(sum( sparse(mod((0:numel(a)-1)',size(a,1))+1,a(:),1)>0,1)); > whos r; > %{ > Name Size Bytes Class Attributes > r 1x200010 1600080 double > %} > % while > au=unique(a); > size(au) > % ans = 20 1 > > just a pedestrian thought... > us I assume OP have posted this thread without random coincidence: http://www.mathworks.com/matlabcentral/newsreader/view_thread/287043 Bruno
First
|
Prev
|
Pages: 1 2 3 Prev: Problem with deployment Next: reassigning values of elements in matrix |