#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Need help with this code please

2»

• Posts: 217Member
Sorry, but I can't understand what you mean.
I can try with an example.
x=[1 1]
y=[1 2]
the euclidean distance is d=sqrt((x(1,1)-y(1,1))^2+(x(1,2)-y(1,2))^2);
in 3 dimension:
x1=[1 1 1]
y1=[1 1 2]
the euclidean distance is d=sqrt((x1(1,1)-y1(1,1))^2+(x1(1,2)-y1(1,2))^2+(x1(1,3)-y1(1,3))^2);
so, if x2 and y2 contain more than a vector:
x2 = [1 2 3; 4 5 6; 7 8 9]
y2 = [ 8 3 4; 5 4 6; 5 6 7]
What I understand is that you want calculate the distance between
[1 2 3] and [8 3 4]
[4 5 6] and [5 4 6]
[7 8 9] and [5 6 7]
so
[code]
for i=1:size(x1,1)
d(i)=sqrt((x1(i,1)-y1(i,1))^2+(x1(i,2)-y1(i,2))^2+(x1(i,3)-y1(i,3))^2);
end
[/code]
Now d contains the 3 distances. (is what you wanted?)

the minimum distance is simply the minimum value of d, so

[code]
min_dist=min(d);
[/code]

· ·
• Posts: 6Member
hi frend,
THE CODE U GIVEN IS STILL HAVING A PROBLEM. IT WONT RUN PROPERLY. CAN U SUGGEST ME CODE FOR THIS
· ·
• Posts: 6Member
This post has been deleted.
· ·
• Posts: 6Member
This post has been deleted.
· ·
2»