필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by