Array of index, should return indexed values on the same array format

4 次查看(过去 30 天)
Hello,
I used knnsearch to find the 100 nearest points from a set of points. I end up having a matrix m=Nx100 that lists all the indexes of the 100 closest to a point. For instance I have (matrix shortened to 4x6):
m=[1 215 106405 210 37814 21780 ; 2 197 13769 21537 40151 40168 ; 3 200 212 503 3375 3943 ; 4 241 250 262 266 271]
Here it means that
The 1st point's 6 closest points are indexes 1, 215, 106405, 210, 37814, 21780
The 2nd point's 6 closest points are indexes 2, 197, 13769, 21537, 40151, 40168
I then have a vector v which represents a weight associated to each points. Hence I would like to have a matrix, Nx100, where each value would be the v(i), something like :
[v(1) v(215) v(106405) v(210) v(37814) v(21780) ; v(2) v(197) v(13769)....................]
I am sure there is a simple way to do it, but I couldn't find the answer.

回答(1 个)

Sindar
Sindar 2020-2-12
It sounds like
weights = v(m);
should work

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by