0

すべての行のサイズが異なるマトリックスがあり、余分な場所はゼロで埋められます。この行列はいくつかの入力引数に依存するため、行数とサイズは固定ではなく動的です。

for e.g.
1 2 4 5 0
1 3 0 0 0
1 2 3 4 5

異なるサイズの n セット (各行から 1 セット) を作成して別の関数に送信する方法 (cartprod http://www.mathworks.com/matlabcentral/fileexchange/5475-cartprod-cartesian-product-of-multiple-sets ?

4

1 に答える 1

0

の入力ベクトルにゼロを入れたくない場合は、次のcartprodように使用できます。

CellArrayWithoutZeros = cellfun(@(x) x(find(x)), num2cell(Matrix, 2), 'UniformOutput', false);

CartProdResultMatrix = cartprod(CellArrayWithoutZeros{:});

編集:の入力ベクトルの先頭のゼロ (非ゼロ要素の右側) のみを切り取りたい場合cartprod:

CellArrayWithoutLeadingZeros = cellfun(@(x) x(1:find(x, 1, 'last')), num2cell(Matrix, 2), 'UniformOutput', false);

CartProdResultMatrix = cartprod(CellArrayWithoutLeadingZeros{:});
于 2012-05-18T12:32:38.093 に答える