Need Help in vectors combinations using ndgrid

10 Ansichten (letzte 30 Tage)
Mahmoud Ahmed
Mahmoud Ahmed am 7 Jun. 2017
Beantwortet: Walter Roberson am 7 Jun. 2017
I have 10 variables (A,B,C,D,E,F,G,H,I,J) .. A consists of 1 vector .. B consists of 19 vectors .. C consists of 21 vectors .. D consists of 19 vectors .. E consists of 34 vectors .. F consists of 83 vectors .. G consists of 34 vectors .. H consists of 20 vectors .. I consists of 20 vectors .. J consists of 20 vectors .. All vectors are with size of (1,10) .. I want to obtain all possible (10,10) matrices that come from all combinations of these variables vectors .. When I wrote this code:
[Xa,Xb,Xc,Xd,Xe,Xf,Xg,Xh,Xi,Xj] = ndgrid(1:size(A,3),1:size(B,3),...
1:size(C,3),1:size(D,3),1:size(E,3),1:size(F,3),...
1:size(G,3),1:size(H,3),1:size(I,3),1:size(J,3));
M = vertcat(A(:,:,Xa(:)),B(:,:,Xb(:)),C(:,:,Xc(:)),...
D(:,:,Xd(:)),E(:,:,Xe(:)),F(:,:,Xf(:)),G(:,:,Xg(:)),...
H(:,:,Xh(:)),I(:,:,Xi(:)),J(:,:,Xj(:)))
MATLAB gives me error and said:
Error using ones
Maximum variable size allowed by the program is exceeded.
Error in ndgrid (line 69)
x = reshape(x(:,ones(1,prod(s))),[length(x) s]); % Expand x
What can I do to fix this problem and obtain all combinations of these (10,10) matrices ?

Antworten (1)

Walter Roberson
Walter Roberson am 7 Jun. 2017
There are at least 1*10*19*21*19*34*83*34*20*20*20 combinations for that -- possibly more depending on what you mean by each variable being a "vector" of size 1 x 10 but also having (for example) 19 vectors.
1*10*19*21*19*34*83*34*20*20*20 = 58190543040000 combinations. That would take at least 58 petabytes to store. I am morally certain that you do not have that much memory available to you.
You will need to give up on your idea of taking all possible combinations and doing some calculation with them.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by