calculating all combinations using nchoosek. A faster way?

조회 수: 1 (최근 30일)
Sabbas
Sabbas 2012년 8월 24일
Dear all, I have a cell matrix A which is of dimension 13048 by 4 I need to calculate all the combinations using the following
J2=nchoosek(1:size(refin_total_input2,1),2);
but it takes a lot of time
I tried to preallocate
J2=zeros(85118628,2);
J2=nchoosek(1:size(refin_total_input2,1),2);
Is there a faster way of obtaining J2
I use matlaab 2009 64 bit
thanks

답변 (1개)

Jan
Jan 2012년 8월 24일
편집: Jan 2012년 8월 24일
The pre-allocation is useless here, because the new values are not inserted, but the original array is overwritten.
Searching the FEX is always a good idea. There you find FEX: VChooseK.mex. I think, this is the fastest implementation, but it needs a compilation. Or you can download the pre-compiled files and install the required runtime libraries of MSVC 2008. An efficient and smart non-Mex version: FEX: combinator.
Beside the speed the C-MEX has the advantage, that it can create the combinations as UINT8/16/32, which occupy less memory than the 8 bytes per double.
  댓글 수: 2
Sabbas
Sabbas 2012년 8월 24일
Hi Jan. what do yuo mean " a compilation" I am not very familiar with these concepts. I downloaded the functions but when I try to run it I obtain the following error
Error in ==> VChooseK at 1
function Y = VChooseK(X, K)
??? Output argument "Y" (and maybe others) not assigned during call to
"D:\Matlab \VChooseK.m>VChooseK".
thanks
Jan
Jan 2012년 8월 24일
편집: Jan 2012년 8월 24일
The help text of the file contains the corresponding explanations: You have to install a compiler, run "mex -setup" and "mex -O VChooseK.c" afterwards.
I will include pre-compiled files on my home page as soon as possible (today if I find the time, but at least this year is guaranteed).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by