Asked by sarah nik
on 24 Jun 2013

Hello Everyone,

I need your help in order to overcome my problem, here is my code:

AP_dist = zeros(N);

for i = 1:N

for j=1:1 p=line([MS_loc(i,1) AP_pos(1,1)], [MS_loc(i,2) AP_pos(1,2)],'Marker','.','LineStyle','-.');

X= [MS_loc(i,1),AP_pos(1,1);MS_loc(i,2),AP_pos(1,2)]; AP_dist= pdist(X,'euclidean') pause(1)

end end

*No products are associated with this question.*

Answer by Andrei Bobrov
on 24 Jun 2013

Edited by Andrei Bobrov
on 24 Jun 2013

Accepted answer

AP_dist= sqrt(sum(bsxfun(@minus,MS_loc,AP_pos).^2,2));

OR

for jj = size(MS_loc,1):-1:1 AP_dist(jj,1) = pdist([MS_loc(jj,:);AP_pos]); end

OR

AP_dist = arrayfun(@(ii)pdist([MS_loc(ii,:);AP_pos]),(1:size(MS_loc,1))');

Opportunities for recent engineering grads.

## 2 Comments

## Matt J (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/80006#comment_156537

And the problem is?

## sarah nik (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/80006#comment_156538

ihave N=5. the problem is. AP_dist just save the latest value. it should have 5 value as my N=5.