MATLAB Answers

creating combinations in the rows of two large multi-dimensional (N-by-M) matrices

8 views (last 30 days)
Samuel Admasie Alene
Samuel Admasie Alene on 7 Jul 2020
I have two large multi dimesional matrices and wanted to create the combination scenarios in row of the two matrices that combination should repeat with the number of column times.
Let
x1=2*ones(5,48);x2=3*ones(5,48);
we know that the number of combinations in row of the two matrices is 25,then I want to perform the following operation
Y=x1+x2
the above operation can be added directly but that is not desired here,I want to creat scenarios for the combinations in rows of x1&x2,,,,resulting matrix Y will be 25 by 48
How can I do that in matlab?

  5 Comments

Show 2 older comments
madhan ravi
madhan ravi on 7 Jul 2020
Mind illustrating with a 2 X 2 matrix?
x1 = [1:2; 3:4]
x2 = [5:6; 7:8]
What would the result be for the above?
Samuel Admasie Alene
Samuel Admasie Alene on 7 Jul 2020
Thanks dear madhan,sure,for the sake of understanding we can illustrate it using lower order possible matrices as u brought here:
x1=[1 2;3 4];
x2=[5 6;7 8];
purpose:to create the follwing different scenarious,
For Column 1
(1,5),(1,6),(3,5) and (3,6)
For Column 2
(3,7),(3,8),(4,7) and (4,8)
Having the above scenarious created I want to do the follwing math manipulation
Y=x1+x2

Sign in to comment.

Answers (1)

KSSV
KSSV on 7 Jul 2020
Read about nchoosek, combnk.
combnk will give you indices, and using these indices you can pick the rows.

  3 Comments

Samuel Admasie Alene
Samuel Admasie Alene on 7 Jul 2020
Thanks for your suggestion,can you explain it more,actually ndgrid() can give us the combination but still we should do the repetation for number of column times.
x1=2*ones(5,48);
x2=3*ones(5,48);
[C1,C2]=ndgrid(x1(:,1),x2(:,1))
for c=1:48
for ct=1:numel(C1)
end
Y=C1(ct)+C2(ct)
end
end
i gave a try as shown above,I am looking help to improve the above trial,
Thanks in advance!
KSSV
KSSV on 7 Jul 2020
There would be 10 combinations, when you select 2 out of 5. nchoosek gives the number of combinations and combnk gives the possilbe combinations.

Sign in to comment.

Categories

Products


Release

R2020a