How to calculate distance from one point base to multipoints and save it as a row?

6 ビュー (過去 30 日間)
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
  2 件のコメント
Matt J
Matt J 2013 年 6 月 24 日
And the problem is?
sarah nik
sarah nik 2013 年 6 月 24 日
ihave N=5. the problem is. AP_dist just save the latest value. it should have 5 value as my N=5.

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 6 月 24 日
編集済み: Andrei Bobrov 2013 年 6 月 24 日
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))');
  1 件のコメント
sarah nik
sarah nik 2013 年 6 月 26 日
thank you very much!! ive tried all of them, and all works well

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 6 月 24 日
AP_dist(i) = pdist(X,'euclidean');
  1 件のコメント
sarah nik
sarah nik 2013 年 6 月 24 日
thank you for this. now i wonder whether i use the correct formula to calculate distance. because it gives different value. please help me AP_dist(i) = pdist(X,'euclidean'); or AP_dist(i) = sqrt((MS_loc(i,1) - AP_pos(j,1))^2 ... + (MS_loc(i,2) - AP_pos(j,2))^2);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by