# How to create a matrix with all possibles cambinations between nodes of 3 sets?

2 views (last 30 days)
Jennifer Arellana on 5 Apr 2021
Hello to all,
I am working in Matlab with data of Ampl, so i am using amplapi. I want to creat a matrix of all possibles combinations between the nodes in the sets O, C and P, but using the data of the parameter CT. For example i have this data:
O = {'O2','O3','O4','O5'}
C = {'C1','C2','C3','C4'}
P = {'P1','P2','P3','P4'}
CTocp = {
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
}
I notice that i have to convert the parameter CTocp in a matrix 3d for it run, so I did the next:
CTocp = reshape(CTocp,4,4,[])
Then, for create a matrix with all possible combination i use:
df_CTocp = DataFrame(3, 'O', 'C', 'P', 'CTocp');
df_CTocp.setMatrix(CTocp, O, C, P)
df_CTocp
The problem is the order that the matrix have, i want that the matrix df_CTocp in the column CTocp has the same order that has the matrix CTocp.

Aditya Patil on 8 Apr 2021
You can use meshgrid function as below
[x,y,z] = meshgrid(C,O,P);
This gives you all combinations of C/O/P.