Cartesian product of row-indices in Matlab
问题 I have a binary matrix A of dimension mxn with m>n in Matlab. I want to construct a matrix B of dimension cxn listing row wise each element of the Cartesian product of the row indices of the ones contained in A . To be more clear consider the following example. Example: %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)