Separate duplicates into different numeric matrices
Mostrar comentarios más antiguos
I have a numeric matrix with duplicate values and want to split the first set from the second set. For example, my matrix looks like this:
100 1 0.44
100 2 0.12
100 3 1.86
100 1 0.02
100 2 3.29
100 3 0.39
101 1 0.32
101 2 0.29
101 3 0.59
101 1 0.00
101 2 0.99
101 3 0.39
I would like to create two matrices that look like the following:
Matrix 1
100 1 0.44
100 2 0.12
100 3 1.86
101 1 0.32
101 2 0.29
101 3 0.59
Matrix 2
100 1 0.02
100 2 3.29
100 3 0.39
101 1 0.00
101 2 0.99
101 3 0.39
Respuestas (2)
Guillaume
el 24 de Jul. de 2017
m = [100 1 0.44
100 2 0.12
100 3 1.86
100 1 0.02
100 2 3.29
100 3 0.39
101 1 0.32
101 2 0.29
101 3 0.59
101 1 0.00
101 2 0.99
101 3 0.39];
[~, iunique] = unique(m(:, [1 2]), 'rows'); %optionally add 'first' or 'last' flag
m1 = m(iunique, :)
m2 = m(setdiff(1:size(m, 1), iunique), :)
Andrei Bobrov
el 24 de Jul. de 2017
a = [100 1 0.44
100 2 0.12
100 3 1.86
100 1 0.02
100 2 3.29
100 3 0.39
101 1 0.32
101 2 0.29
101 3 0.59
101 1 0.00
101 2 0.99
101 3 0.39];
b = sortrows(a,1:2);
out = {b(1:2:end,:);b(2:2:end,:)};
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!