From: ravi on
Hi guys,


I have the following matrix:

X = [ 1 2 3; 4 5 6; 7 8 9]

In matlab it looks like this:
>> X = [ 1 2 3; 4 5 6; 7 8 9]

X =

1 2 3
4 5 6
7 8 9

However, if I want to get X to output with randomly sampled rows for example,:

X =

4 5 6
1 2 3
7 8 9

OR

X =

7 8 9
4 5 6
1 2 3

and so forth for all different possible combinations , what can i do?


Thanks
Ravi

From: Wayne King on
"ravi " <ravi_071(a)hotmail.com> wrote in message <hvriqn$h5g$1(a)fred.mathworks.com>...
> Hi guys,
>
>
> I have the following matrix:
>
> X = [ 1 2 3; 4 5 6; 7 8 9]
>
> In matlab it looks like this:
> >> X = [ 1 2 3; 4 5 6; 7 8 9]
>
> X =
>
> 1 2 3
> 4 5 6
> 7 8 9
>
> However, if I want to get X to output with randomly sampled rows for example,:
>
> X =
>
> 4 5 6
> 1 2 3
> 7 8 9
>
> OR
>
> X =
>
> 7 8 9
> 4 5 6
> 1 2 3
>
> and so forth for all different possible combinations , what can i do?
>
>
> Thanks
> Ravi
>

Hi Ravi, Do you just want randomly-selected permuations? or are you really looking for all possibilities? I wasn't sure from your post. If you want to get random permutations:

X = [ 1 2 3; 4 5 6; 7 8 9];
Indices = randperm(size(X,1));
X(Indices,:)

Wayne
From: Matt Fig on
x(randperm(size(x,1)),:)
From: ravi on
hi wayne,

i'm looking for all possibilities.

thanks for your help
ravi
From: Matt Fig on
% Sample data
x = reshape(randperm(8),4,2);

% One of many approaches to the problem: Store result in a cell array.
D = size(x,1);
D = mat2cell(perms(1:D),ones(prod(1:D),1),D);
D = cellfun(@(t) x(t,:),D,'Un',0)