Extract whole line from array if one value is amongst the x smallest

1 visualización (últimos 30 días)
I'm calculating the distance between one point and several other points (stored in an array, let's call it storageArray(index,<several more indices>, x1, x2, x3). Of the hundreds of points in my array, I only calculate the distances for a few dozens at a time. I then store the calculated distances and their index in another array (distanceArray(index, distance)). This works fine.
I then want to copy the storageArray's lines of the points that yield the x smallest distances (usually 3-5). How do I go about that?
On my search for a solution found a few that I could use to determine the x smallest from an array but I can't seem to find a solution that keeps the indices (which I'd need to copy the right lines) of those x smallest elements. I'm sure I'm probably just missing something obvious and am probably thinking too complicated about it.

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Feb. de 2014
[sortedvals, sortidx] = sort(YourValues(:,1));
YourValues(sortidx(1),:)
YourValues(sortidx(2),:)

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by