Extract two closest rows of a matrix
1 view (last 30 days)
Show older comments
Hello,
How can I extract two closest rows of a matrix and set one of them to zero?
thank you.
3 Comments
Image Analyst
on 20 Mar 2016
Well, here is the "set to zero" part
yourMatrix(closestRow, :) = 0;
to determine what scalar value you need for closestRow, you need to answer dpb's question.
Accepted Answer
dpb
on 21 Mar 2016
d=pdist(M(:,2)); % find the pairwise differences
ix=find(min(d(1:end-1)); % shortest distance excluding wraparound of 3-1
M(ix,:)=[]; % remove that row
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!