How to find the closest value between a matrix and a vector and print out its index?

3 次查看(过去 30 天)
For example the vector is [3 4 5 6] and the matrix is a 4x4, i want to compare each element of the matrix with the vector and place all indices of the four near elements in a vector.
  3 个评论
Mohannad Alzard
Mohannad Alzard 2020-9-26
The elements of the vector are compared with all the elements of the matrix, and the nearest value from the matrix with respect to the vector its index is placed in a another vector, this should be repeated until all the elements of the vectors are compared with the elements of the matrix.

请先登录,再进行评论。

采纳的回答

David Hill
David Hill 2020-9-26
You mean something like this?
I=[];
for k=1:length(v)
[~,idx]=min(abs(m-v(k)),[],'all','linear');
I=[I,idx];
end

更多回答(0 个)

类别

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