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

1 回表示 (過去 30 日間)
mosch
mosch 2014 年 2 月 5 日
コメント済み: mosch 2014 年 2 月 5 日
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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by