|
"us " <us@neurol.unizh.ch> wrote in message <i1qcj8$idl$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i1qb9c$oo4$1@fred.mathworks.com>...
> > Another solution:
> >
> > a=[1 2 2;
> > 2 3 3;
> > 1 4 5];
> >
> > sum(accumarray([mod((0:numel(a)-1)',size(a,1))+1 a(:)],1)>0)
> >
> > Bruno
>
> the problem with all these nice solutions
> - given the OP's mat size...
>
> a=ceil(4000*rand(1e5,5));
> sum(accumarray([mod((0:numel(a)-1)',size(a,1))+1 a(:)],1)>0)
> %{
> ??? Error using ==> accumarray
> Out of memory. Type HELP MEMORY for your options.
> %}
> % same with the HISTC approach...
>
> us
tic
A=ceil(4000*rand(1e5,5));
Acell = cellfun(@unique,mat2cell(A,ones(1,size(A,1)),size(A,2)),'UniformOutput',false);
U = unique(A);
[n] = histc(cell2mat(Acell'),U);
table = [U, n']; %U is the value n is the occurance
toc
%Elapsed time is 4.247591 seconds.
%table = 4000 x 2 double
|