Hi Josh:
Let A = 3 \times na be an array with the coordinates of anchor 'j' in the jth column.
and similarly for S = 3 \times ns
D = repmat(S(:, i), 1, na)  A; % each column is a threevector,
% giving the Euclidean representation
% of the vector from anchor 'j'
% to seat 'i'
d = (sum(D.^2)).^(.5); % D.^2 is the componentwise square of D,
% sum gives the column sum(s)
% .^(.5) takes the square root of elements
% of d
d is a row
d(j) is the Euclidean distance from seat 'i' to anchor 'j'.
Use a for loop on 'i' for the seats of interest.
gene
"Josh Meyer" <jmeyer@mathworks.com> wrote in message <kpafoo$3o3$1@newscl01ah.mathworks.com>...
> >> How do I write a code to calculate the distance between, lets say, Seat
> >> [1 2 3] to all 5 anchors?
>
> The Euclidean distance between two points is equal to the 2norm of the
> difference. So the distance from the point [1 2 3] to the point [1 1 1] is
> equal to sqrt(0^2 + 1^2 + 2^2), or sqrt(5). In MATLAB this is norm([1 2 3] 
> [1 1 1]).
>
> >> Then, I need to keep that distance and calculate the same thing will all
> >> of the Seats.
>
> There is probably a way to do this without so many loops, but one way to do
> it is:
> 
> D = zeros(length(Seats),length(Anchors));
> for i = 1:length(Seats)
> for j = 1:length(Anchors)
> D(i,j) = norm(Seats(i,:)  Anchors(j,:));
> end
> end
> 
> D =
>
> 2.2361 1.4142 2.2361 3.7417 5.3852
> 3.7417 2.2361 1.4142 2.2361 3.7417
> 5.3852 3.7417 2.2361 1.4142 2.2361
> 7.0711 5.3852 3.7417 2.2361 1.4142
> 8.7750 7.0711 5.3852 3.7417 2.2361
> 10.4881 8.7750 7.0711 5.3852 3.7417
> 12.2066 10.4881 8.7750 7.0711 5.3852
> 13.9284 12.2066 10.4881 8.7750 7.0711
> 15.6525 13.9284 12.2066 10.4881 8.7750
>
> The first row of D is the distance from the first Seat, [1 2 3], to each
> Anchor, the second row is the distance from the second Seat, [2 3 4], to
> each Anchor, etc...
