我有一個二維矩陣A
的尺寸mxn
與m>n
在Matlab中。我想構建一個尺寸爲cxn
的矩陣B
,列出A
中包含行索引的笛卡爾乘積的每個元素。要更清楚地考慮下面的例子。在Matlab中的行索引的笛卡爾乘積
例子:
%m=4;
%n=3;
A=[1 0 1;
0 0 1;
1 1 0;
0 0 1];
%column 1: "1" are at rows {1,3}
%column 2: "1" are at row {3}
%column 3: "1" are at rows {1,2,4}
%Hence, the Cartesian product {1,3}x{3}x{1,2,4} is
%{(1,3,1),(1,3,2),(1,3,4),(3,3,1),(3,3,2),(3,3,4)}
%I construct B by disposing row-wise each 3-tuple in the Cartesian product
%c=6
B=[1 3 1;
1 3 2;
1 3 4;
3 3 1;
3 3 2;
3 3 4];
警告。 'combvec'屬於神經網絡工具箱。 – rayryeng