How can I only keep keys that have the smallest value pair in a matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to create an edge detection program that creates a matrix with coordinates of just the surface of whatever subject we're examining. After using the canny edge detection filter I have all the coordinates of what the filter is calling the surface, which includes multiple rows within the same column. I'm trying to create a new matrix such that only the smallest row number numbers are assigned to each column.
For instance, If I have an n x 2 array like
A = [1 10; 1 15; 1 20; 2 35; 2 46; 2 57;]
I would want an output that looks like
B = [1 10; 2 35]
0 comentarios
Respuestas (1)
Walter Roberson
el 18 de Jun. de 2019
[g, val] = findgroups(A(:,1));
B = [val, accumarray(g, A(:,2), [], @min)];
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!