Created
June 4, 2011 09:53
-
-
Save vertexclique/1007765 to your computer and use it in GitHub Desktop.
finding the distance between two vectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function y = distance(a,b) | |
if length(a) == length(b) | |
size = length(a); | |
if size < 2 | |
error('The vectors size must greater than one'); | |
end; | |
else | |
error('Vectors size not equal each other'); | |
end; | |
total=0; | |
for i = 1:size | |
total = total + (a(i)- b(i)).^2; | |
end; | |
y = sqrt(total); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment