필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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!

답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by