0

I am using the following code to get all the possible combinations of the rows of a matrix.

function rComb(matrix)
rows =  size(matrix,1)
for n = 1:rows

    rowsCell = num2cell(matrix,2);
    r = nchoosek(1:size(matrix,1),n);
    out = cell2mat(reshape(rowsCell(r.',:).',n,1,[]))
end
end

Now I want to take the transpose of the out variable, and I am using this code.

function rComb(matrix)
rows =  size(matrix,1)
for n = 1:rows

    rowsCell = num2cell(matrix,2);
    r = nchoosek(1:size(matrix,1),n);
    out = cell2mat(reshape(rowsCell(r.',:).',n,1,[]))
    transp = out'
end
end

And I am facing this error...!!

"Error using ' Transpose on ND array is not defined. Use PERMUTE instead."

  1. Can you solve this issue?

  2. One more thing can a function give us multiple outputs like all the possible combinations of output? Like in the above code if I place ';' after out variable statement this function won't display anything :/.

  • ...have you tried using [`permute()`](https://nl.mathworks.com/help/matlab/ref/permute.html) instead of [`.'`](https://nl.mathworks.com/help/matlab/ref/ctranspose.html)? – Rody Oldenhuis Nov 14 '17 at 19:40
  • I am not familiar with this permute function I don't know how to use that here :/ – Ali Hassan Nov 14 '17 at 19:41
  • 1
    type `help permute` in MATLAB (or click on the links above) to find out! :) – Rody Oldenhuis Nov 14 '17 at 19:42
  • One more thing can a function give us multiple outputs like all the possible combinations of output? Like in the above code if I place ';' after out variable statement this function won't display anything. – Ali Hassan Nov 14 '17 at 19:47
  • Then collect the outputs in a variable, something like `transpose{n} = out'`. Oh and, avoid using `transpose` as a variable name, because it is also the name of a function in MATLAB. – Rody Oldenhuis Nov 14 '17 at 19:51
  • I tried help permute it doesn't make any sense -_- :3 – Ali Hassan Nov 14 '17 at 19:51
  • It does take some getting used to, that's certainly true. Transposing a matrix is like flipping the rows with the columns, right? That's equal to `permute(A, [2 1])`. Read it like so: "put dimension '2' in 1ˢᵗ place, dimension '1' in 2ⁿᵈ place. – Rody Oldenhuis Nov 14 '17 at 19:55
  • More elaborate example: `permute(A, [2 1 4 3])` ≣ "put dimension '2' in 1ˢᵗ place, dimension '1' in 2ⁿᵈ place, dimension '4' in 3ʳᵈ place, and dimension '3' in 4ᵗʰ place. – Rody Oldenhuis Nov 14 '17 at 19:55
  • 1
    Does this help?: [How does the permute function in matlab work](https://stackoverflow.com/q/21100168/52738) – gnovice Nov 14 '17 at 20:02

0 Answers0