v = uint16([1 10 11 12 13 14 16 18 21 22 23 24 26 32 35 36 37 39 41 42 44 46 56 57 58 59 62 66 68 69 71 72 73 77 80]);
C = nchoosek(v,uint16(22))
I try this code for combination but use memory in matlab is very huge and take time
Can you help me?

 채택된 답변

John D'Errico
John D'Errico 2015년 9월 21일

2 개 추천

Why do people never think about what they wish to do? Computers are not infinite in size, nor are they all powerful except on tv.
v = [1 10 11 12 13 14 16 18 21 22 23 24 26 32 35 36 37 39 41 42 44 46 56 57 58 59 62 66 68 69 71 72 73 77 80];
numel(v)
ans =
35
nchoosek(35,22)
ans =
1.4763e+09
So your call to nchoosek will tell MATLAB to create an array of size: 1.5e9 by 22.
Even as uint16, that matrix will require 2 bytes per element.
1.5e9*22*2
ans =
6.6e+10
So 66 gigabytes of RAM, just to create that matrix. It might take some time to do, even if you have close to that much RAM. Most likely, your disk started swapping like mad.
Computers do have finite capabilities.

댓글 수: 2

akyanus
akyanus 2015년 9월 21일
Thank you John :)
Using the duration functionality we can also tell how long it would take to operate on that data at a rate of one combination processed per second.
years(seconds(nchoosek(35, 22)))
The SECONDS call creates a duration representing a number of seconds, and the YEARS call converts that duration into the equivalent number of exact years.
At a little over 46 3/4 years you might want to rethink your approach, see if you can parallelize your operation, or wait a little while and see if Moore's law continues to hold.

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

추가 답변 (1개)

Jan
Jan 2015년 9월 21일
편집: Jan 2015년 9월 21일

0 개 추천

If the values of your vector are smaller than 256, you can convert them in the type uint8 and use FEX: vchookek.mex . Matlabs nchoosek used double values, at least in older Matlab versions. Reducing the tapy of the data as far as possible might allow to squeeze the data into your RAM.
There are many other useful submissions in the FileExchange, e.g. FEX:a-fast-nchoosek-alternative-for-engineers-who-like-fast-nchoosek-alternatives

댓글 수: 2

akyanus
akyanus 2015년 9월 28일
I couldn't use this code, because I don't know how call this function Jan
Jan
Jan 2015년 9월 29일
See "help vchoosek" for detailed instructions. Either compile the code or download the precomiled file from the provided link. Then call this function exactly as you would call Matlab's nchoosek.

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

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

질문:

2015년 9월 21일

댓글:

Jan
2015년 9월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by