# How to get all combinations from this matrix?

1 view (last 30 days)
Robu Robert on 21 Apr 2021
Answered: Bruno Luong on 24 Apr 2021
Hello, everyone! Can someone help me with this? I want to use allcomb function for any matrix, any ideas how can I do this besides writing down every line of the vector?
ch=['MRWI'
'IDMZ'
'CGBI'
'JKNO']
v=[];
[x,y]=size(ch);
allcomb(ch(1,:),ch(2,:),ch(3,:),ch(4,:))
##### 2 CommentsShowHide 1 older comment
Robu Robert on 21 Apr 2021
The output should be all possible combinations between letters of the rows, taken 1 from each row. I pasted down the correct output. My question is how to generalize allcomb(ch(1,:),ch(2,:),ch(3,:),ch(4,:)) to work for every input matrix.
'MICJ'
'MICK'
'MICN'
'MICO'
'MIGJ'
'MIGK'
'MIGN'
'MIGO'
'MIBJ'
'MIBK'
'MIBN'
'MIBO'
'MIIJ'
'MIIK'
'MIIN'
'MIIO'
'MDCJ'
'MDCK'
'MDCN'
'MDCO'
'MDGJ'
'MDGK'
'MDGN'
'MDGO'
'MDBJ'
'MDBK'
'MDBN'
'MDBO'
'MDIJ'
'MDIK'
'MDIN'
'MDIO'
'MMCJ'
'MMCK'
'MMCN'
'MMCO'
'MMGJ'
'MMGK'
'MMGN'
'MMGO'
'MMBJ'
'MMBK'
'MMBN'
'MMBO'
'MMIJ'
'MMIK'
'MMIN'
'MMIO'
'MZCJ'
'MZCK'
'MZCN'
'MZCO'
'MZGJ'
'MZGK'
'MZGN'
'MZGO'
'MZBJ'
'MZBK'
'MZBN'
'MZBO'
'MZIJ'
'MZIK'
'MZIN'
'MZIO'
'RICJ'
'RICK'
'RICN'
'RICO'
'RIGJ'
'RIGK'
'RIGN'
'RIGO'
'RIBJ'
'RIBK'
'RIBN'
'RIBO'
'RIIJ'
'RIIK'
'RIIN'
'RIIO'
'RDCJ'
'RDCK'
'RDCN'
'RDCO'
'RDGJ'
'RDGK'
'RDGN'
'RDGO'
'RDBJ'
'RDBK'
'RDBN'
'RDBO'
'RDIJ'
'RDIK'
'RDIN'
'RDIO'
'RMCJ'
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