Splitting a matrix in subsets??

Dear experts, I have a scenario matrix from which I would like to generate a binary tree, the binary tree structure matrix is as follow:
if true
% code
M= [8 25 25 25 25 25;
8 25 36 36 36 36;
8 25 25 15 15 15;
8 25 36 50 50 50;
8 25 25 10 10 10;
8 25 25 6 6 6;
8 25 36 70 70 70;
8 25 25 3 3 3];
end
where 1st and 2nd row are mother scenarios and the rest are the branching scenarios. I would like to seperate this matrix to these two scenario that which rows is a subset of which mother row. so that the end result should be
if true
%
M1 = [8 25 25 25 25 25;
8 25 25 15 15 15;
8 25 25 10 10 10;
8 25 25 6 6 6;
8 25 25 3 3 3];
%
M2 = [8 25 36 36 36 36;
8 25 36 50 50 50;
8 25 36 70 70 70];
end

2 commentaires

Geoff Hayes
Geoff Hayes le 7 Août 2014
Modifié(e) : Geoff Hayes le 7 Août 2014
Usman - in your example, M1 and M2 have three rows in common. How are you determining which row belongs to which mother row?
Ohhhh my Bad :( , let me correct it. Actually the M1 includes all the branches of [8 25 25 25 25 25] and M2 includes all the branches connected to [8 25 36 36 36 36].
if true
% code
M1 = [8 25 25 25 25 25; 8 25 25 15 15 15;
8 25 25 10 10 10; 8 25 25 6 6 6;
8 25 25 3 3 3];
%
M2 = [8 25 36 36 36 36; 8 25 36 50 50 50;
8 25 36 70 70 70];
end

Connectez-vous pour commenter.

Réponses (2)

Iain
Iain le 7 Août 2014

0 votes

M = [8 25 25 25 25 25; 8 25 36 36 36 36; 8 25 25 15 15 15;
8 25 36 50 50 50; 8 25 25 10 10 10; 8 25 25 6 6 6;
8 25 36 70 70 70; 8 25 25 3 3 3];
M1 = M(1:2:(end-1),:);
M2 = M(2:2:(end),:);

5 commentaires

Iain
Iain le 7 Août 2014
Change the 1:2:end-1 etc. with the appropriate list.
Usman  Ali
Usman Ali le 7 Août 2014
does not solves my problem, Sorry I do not get it, what shall be an appropriate list in the above case??
Iain
Iain le 7 Août 2014
To match your example:
The first list (for M1) is: [1 3 5 6 8]
The second list (for M2) is: [2 4 5 6 8]
Why that matches your example, I do not know.
Usman  Ali
Usman Ali le 7 Août 2014
I guess your ans is some what manual. the posted matrix is just an example, in real i have a very big matrix of [7000 x 50]. what if the order of rows is changed that's why I need some automatic solution that should compare the selected rows with mother row and splitt them into different subsets.
Iain
Iain le 11 Août 2014
You need some logic that fills in the lists.
If the first list is defined by rows that have 25 in the 3rd column, then the first list is:
list1 = find(M(:,3) == 25);

Connectez-vous pour commenter.

Adam
Adam le 11 Août 2014

0 votes

M1 = M( M(:,3) == 25,:)
M2 = M( M(:,3) == 36,:)
would seem to do the job in that case though that assumes that column 3 contains the value that distinguishes the two branching paths, irrespective of the values in the other columns.

Catégories

En savoir plus sur Software Development Tools dans Centre d'aide et File Exchange

Question posée :

le 7 Août 2014

Commenté :

le 11 Août 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by