Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1076
Number of posts: 1755

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with find euclid distance with set of data points Posted by eselocoss on 26 Apr 2009 at 11:34 AM
So I have to write a function that will find the euclidean distance between every pair of points, given a set of data points X. Can anyone help me with this. I am not very good with Matlab.

function [DM] = distance_matrix (X)


Assume that data points in X are represented by the rows of that matrix (there is no class label or
target value in the last column).

Note that you can build this function from code knn.m (attached here) with
minor modifications. Example output you can use to test your code:

X = [1 2 3 4; 5 6 7 8; 9 10 11 12];
distance_matrix(X)

ans = 0 8 16
8 0 8
16 8 0
Attachment: knn.m (1701 Bytes | downloaded 91 times)
Report
Re: Help with find euclid distance with set of data points Posted by giug on 26 Apr 2009 at 1:16 PM
Here is the code to find the distance matrix:

y = pdist(X,'euclidean')
dist_mat=squareform(y)


If you have other questions please post in www.sosmatlab.com. I will not answer here in the future.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.