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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Mohannad Alzard
Mohannad Alzard am 26 Sep. 2020
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by