How to find the closest value between a matrix and a vector and print out its index?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohannad Alzard
am 26 Sep. 2020
Kommentiert: Mohannad Alzard
am 26 Sep. 2020
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
Akzeptierte Antwort
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)
Siehe auch
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!