Asked by osman
on 18 Sep 2019 at 12:41

Hello There!

I have N number of vectors recorded into workspace. I need to perform combination among themselves by using allcomb. How could I introduce the vectors into the command (allcomb) in the form of B = ALLCOMB(A1,A2,A3,...,AN).

Thanks inadvance....

Answer by Bruno Luong
on 18 Sep 2019 at 12:47

Create a CELL array, and get rid of the method of naming your variables with number 1,2,....

C = {A1, A2, A3, ..., AN}

B = allcomb(C{:});

Bruno Luong
on 19 Sep 2019 at 10:12

Do you understand when I wrote:

"They compule two different things."

% Example

U=bsxfun(@plus,(1:2),[0:2:6]')

% Your's

Your1 = allcomb(U(1,:),U(2,:),U(3,:),U(4,:))

% Your again

C=cell(size(U,1),1);

for k = 1:size(U,1)

C{k}=eval('U(k,:)');

end

Your2 = allcomb(C{:})

% Jos's

C = mat2cell(U, size(U,1), ones(1,size(U,2)));

Jos = allcomb(C{:})

% Bruno's

C = mat2cell(U, ones(1,size(U,1)), size(U,2));

Bruno = allcomb(C{:})

osman
on 19 Sep 2019 at 10:23

Thanks so much! I really appreciate about what you made me recognize.

Jos (10584)
on 19 Sep 2019 at 20:22

Thanks Bruno, for correcting me, and thereby helping osman :-)

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Adam (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/480945-using-allcomb-for-unknown-number-of-vectors#comment_747254

## osman (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/480945-using-allcomb-for-unknown-number-of-vectors#comment_747270

## John D'Errico (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/480945-using-allcomb-for-unknown-number-of-vectors#comment_747278

Sign in to comment.