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 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!