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

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2014-2-5
[sortedvals, sortidx] = sort(YourValues(:,1));
YourValues(sortidx(1),:)
YourValues(sortidx(2),:)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by