comparing between two arrays

sorry if my question is trivial , but i'm still beginner and need your help. i have 3 points in the space say a , b, c each one is an array 2x3 , say a=[2 3 4 ; 9 8 7] ,b =[ 5 2 1 ; 6 3 2] , c=[ 4 7 1; 1 2 3]. i want to compare the distance between points a and b (dist12) with the distance between a and c (dist13), which is longer? thank you

댓글 수: 5

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 6일
A point in the space is represented by 1x3 array not 2x3
Mohammad Monfared
Mohammad Monfared 2013년 10월 6일
Azzi is right. assuming a and b are two points in 3-D space ( each have 3 components), their euclidean distance is: norm(a-b).
mariam
mariam 2013년 10월 7일
you are right, but i'm working in clustering using particle swarm. each particle has 2 clusters, so for me the point (particle)has two objects , so when i said a=[2 3 4 ; 9 8 7] this mean the first row is for cluster 1 in particle 1 and second row is for cluster 2 in particle 1. i hope it's clear
Jan
Jan 2013년 10월 7일
@mariam: No, it is not clear enough. "Distance" is defined for single points only. Therefore it is not uniquely defined, what you are looking for.
mariam
mariam 2013년 10월 8일
ok , i will explain with more details , i work in clustering using particle swarm . for example i have 3 particles each one has 2 cluster (this is why each array has two rows). a is particle 1 , b is particle 2 , particle 3 is c . particle 1 (a) is the best solution. so i want to compute the max distance of the particles (b , c ) from particle (a). l know how to compute the euclidean distance from each array to (a). for example distance ab =[ 4.3589 ; 11] and distance ac = [ 5.3852 ;3]. i want to compute max distance .

댓글을 달려면 로그인하십시오.

답변 (2개)

David Sanchez
David Sanchez 2013년 10월 7일

0 개 추천

a=[2 3 4 ; 9 8 7];
b =[ 5 2 1 ; 6 3 2];
c=[ 4 7 1; 1 2 3];
dist_ab_cluster_1 = norm(b(1,:)-a(1,:));
dist_ab_cluster_2 = norm(b(2,:)-a(2,:));
dist_ac_cluster_1 = norm(c(1,:)-a(1,:));
dist_ac_cluster_2 = norm(c(2,:)-a(2,:));
dist_ab_cluster_1 =
4.3589
dist_ab_cluster_2 =
7.6811
dist_ac_cluster_1 =
5.3852
dist_ac_cluster_2 =
10.7703

댓글 수: 1

mariam
mariam 2013년 10월 7일
thank you very much , but if i want to treat the particle which contains two cluster as one unit ....i mean to compare between the array p1= [4.3589 ; 7.6811] and p2=[5.3852 ;10.7703] to know which distance is longer . thank you

댓글을 달려면 로그인하십시오.

Andrei Bobrov
Andrei Bobrov 2013년 10월 7일

0 개 추천

a=[2 3 4 ; 9 8 7]; b =[ 5 2 1 ; 6 3 2]; c=[ 4 7 1; 1 2 3];
data = cat(3,a,b,c);
s = size(data);
t = reshape(data(:,:,nchoosek(1:s(3),2)') , s(1),s(2),2,[]);
out = squezze(sqrt(sum(diff(t,[],3).^2,2)));

댓글 수: 3

mariam
mariam 2013년 10월 8일
out =[ 4.35889894354067 5.38516480713450 5.09901951359278 7.68114574786861 10.7703296142690 5.19615242270663] i notice that first column is distance ab , second column is distance ac , but i didn't understand the third column
Andrei Bobrov
Andrei Bobrov 2013년 10월 8일
distance between a and b
mariam
mariam 2013년 10월 9일
ok thank you , but if i want to know which is the max distance what i can do. a-b , or a-c

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

질문:

2013년 10월 6일

댓글:

2013년 10월 9일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by