Splitting a matrix in subsets??
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2014-8-7
编辑:Geoff Hayes
2014-8-7
Usman - in your example, M1 and M2 have three rows in common. How are you determining which row belongs to which mother row?
回答(2 个)
Iain
2014-8-7
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 个评论
Iain
2014-8-11
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);
Adam
2014-8-11
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!