フィルターのクリア

Associate indices with matrix row

1 回表示 (過去 30 日間)
Danilo M
Danilo M 2018 年 7 月 25 日
編集済み: Adam Danz 2018 年 7 月 25 日
I need to find nearest gauge stations for a list of points. After calculate the distance from stations to each point, I'm using this code to return the minimum values of distance:
[minValues, minIndices] = min(dist,[],2)
How can I capture the first row of gauge station list for each indice?
i.e. for this matrix minValues = [2; 3; 2; 5] gauge = [12; 23; 34; 45; 56; 67]
it creates anoter like [2 23; 3 34; 2 23; 5 56]

回答 (1 件)

Adam Danz
Adam Danz 2018 年 7 月 25 日
編集済み: Adam Danz 2018 年 7 月 25 日
Your question is unclear but I think I get what you're asking.
I assuming 'dist' is a matrix of distances were columns are gauge stations and rows are 'points' such that dist(i,j) is the distance between point(i) and station(j).
minValues(i) is the minimum distance between point(i) and all of the gauge stations (or the other way around, depending on how your matrix is organized).
minIndices(i) is the column number of 'dist' that contains the minimum for row(i). In other words, minIndices(i) tells you the gauge station that is closest to point(i).
To summarize, minValues(1:5) are the minimum distances for points(1:5) and the nearest gauge stations for those points are minIndices(1:5).
To create a linear index of the 'dist' matrix:
x = sub2ind(size(dist), 1:length(minIndices), minIndices');

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by