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
Answered: Aditya Patil on 8 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 = {[196]
[146],
[154],
[244],
[317],
[129],
[140],
[224],
[246],
[256],
[314],
[161],
[333],
[292],
[245],
[183],
[296],
[246],
[222],
[293],
[291],
[138],
[174],
[174],
[229],
[227],
[164],
[166],
[176],
[115],
[184],
[237],
[305],
[316],
[128],
[158],
[234],
[345],
[211],
[142],
[313],
[330],
[135],
[315],
[262],
[208],
[286],
[172],
[305],
[316],
[128],
[158],
[196],
[146],
[154],
[244],
[313],
[330],
[135],
[315],
[296],
[246],
[222],
[293]}
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.
Please someone help me!
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Answers (1)

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.
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Categories

Find more on Logical in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!