From: Ozge Taskan on
Hi everyone,

I have a matrix like

S_new =

2 6 11 0
0 0 2 0
0 1 2 0
0 1 2 0
1 3 6 0

and by taking one number from each row I would like to find each possible combinations of number for example:

2,0,0,0,1
2,0,0,0,3
2,0,0,0,6
2,0,0,0,0
6,0,0,0,1
6,0,0,0,3
....
..
..
..
11,0,2,1,6

one number is taken from first row, one number from second row, one number from third row .... like this but every time one number from one row( rows should be in orders from first,second, thurd, fourth, fifth row) and like this I should look at the every combinations, can it be possible?

Thank you in advance.

Kind regards,

Ozge
From: Matt Fig on
One method:


% Data
A =[2 6 11 0;0 0 2 0;0 1 2 0;0 1 2 0;1 3 6 0]

% Engine
[m,n] = size(A);
G = A(npermutek(0:(n-1),m) * m + repmat(1:m,n^m,1));

Where npermutek is here:

http://www.mathworks.com/matlabcentral/fileexchange/11462-npermutek
From: Ozge Taskan on
thank you very much, this is exactly what I want. Can I ask one more question? Is it possible to write the the rank of the number that is chosen in another matrix, I mean this time one matrix will write the rank of the numbers in the row? Is it possible?

Thank you very much in advance.

Ozge
From: Matt Fig on
I do not know what you mean by "rank of a number." I usually think of the rank as the number of independent rows (or columns) in a matrix.

http://mathworld.wolfram.com/MatrixRank.html
From: Jos (10584) on
"Ozge Taskan" <lordgy(a)yahoo.com> wrote in message <hsrjq4$9t0$1(a)fred.mathworks.com>...
> Hi everyone,
>
> I have a matrix like
>
> S_new =
>
> 2 6 11 0
> 0 0 2 0
> 0 1 2 0
> 0 1 2 0
> 1 3 6 0
>
> and by taking one number from each row I would like to find each possible combinations of number for example:
>
> 2,0,0,0,1
> 2,0,0,0,3
> 2,0,0,0,6
> 2,0,0,0,0
> 6,0,0,0,1
> 6,0,0,0,3
> ...
> .
> .
> .
> 11,0,2,1,6
>
> one number is taken from first row, one number from second row, one number from third row .... like this but every time one number from one row( rows should be in orders from first,second, thurd, fourth, fifth row) and like this I should look at the every combinations, can it be possible?
>
> Thank you in advance.
>
> Kind regards,
>
> Ozge

% a smaller example:
A = [1 2 3 ; 11 12 13]
% engine
RowRank = combn(1:size(A,2),size(A,1))
B = A(sub2ind(size(A),repmat(1:size(A,1),size(RowRank,1),1),RowRank))

COMBN can be download on the FEX:
http://www.mathworks.com/matlabcentral/fileexchange/7147-combn

hth
Jos
 |  Next  |  Last
Pages: 1 2
Prev: Fitting a surface
Next: plot a 3D table