Got something to write about? Check out our Article Builder.

Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 597
Number of posts: 1018

This Forum Only
Post New Thread

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 36 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.



 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 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.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A BootstrapLabs project.