Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将多个不同大小的集合发送到matlab函数?_Matlab_Parameters_Matrix_Arguments_Argument Passing - Fatal编程技术网

如何将多个不同大小的集合发送到matlab函数?

如何将多个不同大小的集合发送到matlab函数?,matlab,parameters,matrix,arguments,argument-passing,Matlab,Parameters,Matrix,Arguments,Argument Passing,我有一个矩阵,其中每一行都有不同的大小,额外的位置用零填充。该矩阵依赖于一些输入参数,因此具有动态的而非固定的行数和大小 for e.g. 1 2 4 5 0 1 3 0 0 0 1 2 3 4 5 如何创建不同大小的n组(每行一组)并将其发送给另一个功能,例如cartprod 如果您不希望在cartprod的输入向量中有任何零,可以使用以下方法: CellArrayWithoutZeros = cellfun(@(x) x(find(x)), num2cell(Matrix, 2), 'Un

我有一个矩阵,其中每一行都有不同的大小,额外的位置用零填充。该矩阵依赖于一些输入参数,因此具有动态的而非固定的行数和大小

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

如何创建不同大小的n组(每行一组)并将其发送给另一个功能,例如cartprod

如果您不希望在
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{:});