全矩阵(matlab)中使用combvec

时间:2020-12-08 21:29:30

I have nxm matrix. I want to use combvec to produce all the possible combinations like this

我有nxm矩阵。我想要用梳子来制作所有可能的组合。

combvec(X(1,:),...,X(m,:))

If my matrix is different for each loop. How can I use the combvec syntax? Do I have to separate it by column? But How?

如果每个循环的矩阵是不同的。我如何使用梳式语法?我必须把它单独列出来吗?但如何?

Example: my matrix

例如:矩阵

L=[25000000 15000000 10000000 5000000 3000000 2000000 1000000 800000 700000 500000 500000 300000 200000 100000 0]
L(2,:)=zeros(1,length(L))

How to avoid inputting one by one like this?

如何避免像这样一个一个地输入?

    combination=combvec([25000000,0],[15000000,0],[10000000,0],[5000000,0],[3000000,0],[2000000,0],[1000000,0],[800000,0],[700000,0],[500000,0],[500000,0],[300000,0],[200000,0],[100000,0],[0,0])';

1 个解决方案

#1


2  

combvec seems to require row vectors, not column vectors. So you need to work tih L transposed, so that columns become rows. You can:

好斗的人似乎需要行向量,而不是列向量。所以需要把tih转置,使列变成行。您可以:

  1. Build a cell array where each row of L transposed goes to a cell;
  2. 构建一个单元数组,其中每一行L转置到一个单元格;
  3. Call combvec using as input a comma-separated list generated from the cell array.
  4. 使用从单元数组中生成的逗号分隔的列表来调用combvec。

That is:

那就是:

L = [25000000 15000000 10000000 5000000 3000000 2000000 1000000 800000 700000 500000 500000 300000 200000 100000 0];
L(2,:) = zeros(1,length(L)); %// example input
L2 = mat2cell(L.', ones(1,size(L,2)), size(L,1)); %// step 1
result = combvec(L2{:}); %// step 2

#1


2  

combvec seems to require row vectors, not column vectors. So you need to work tih L transposed, so that columns become rows. You can:

好斗的人似乎需要行向量,而不是列向量。所以需要把tih转置,使列变成行。您可以:

  1. Build a cell array where each row of L transposed goes to a cell;
  2. 构建一个单元数组,其中每一行L转置到一个单元格;
  3. Call combvec using as input a comma-separated list generated from the cell array.
  4. 使用从单元数组中生成的逗号分隔的列表来调用combvec。

That is:

那就是:

L = [25000000 15000000 10000000 5000000 3000000 2000000 1000000 800000 700000 500000 500000 300000 200000 100000 0];
L(2,:) = zeros(1,length(L)); %// example input
L2 = mat2cell(L.', ones(1,size(L,2)), size(L,1)); %// step 1
result = combvec(L2{:}); %// step 2