How to find distance between different points in a dataset as shown in scatter plot

3 ビュー (過去 30 日間)
Arsal15
Arsal15 2016 年 2 月 4 日
コメント済み: Brendan Hamm 2016 年 2 月 4 日
Hi,
This is my scatter plot data of 5 simulated points and data in blue is my reference point and I want to compute the distance of this blue data from other data set one by one. As all data sets are of equal dimension [1x51] and when I am computing the distance then it is giving me error of Sub-scripted assignment dimension mismatch.
I have attached the ns.mat file and I want distance matrix with distance of (1 from 2),(1 from 3),(1 from 4),(1 from 5). Need your guidance.
if true
for time = 0:0.2:10
for i=1:numData
for j=1:len_data
% Get first sensor x and y coordinates
tx = [ns(1).x];
ty = [ns(1).y];
% Compute distances
distance_nhood(i,j) = sqrt((tx- ns(i).x(j)).^2 + (ty- ns(i).y(j)).^2);
% If distance is less than 5, draw a line to it.
% First find which nodes are closest.
neighbourNodes = find(distance_nhood < 5);
.............
%%coding continue
.............
end
end
connMatrix = ( distance_nhood< txRange);
% Get the number of reachable neighbors
neighborNodes = find(neighbourNodes (1, :) == 1); % logic to think
% Get the unreached neighbors
neigbborNodes = intersect(neighborNodes, find(visited(:) == 0));% logic to think
end
  4 件のコメント
Arsal15
Arsal15 2016 年 2 月 4 日
編集済み: Arsal15 2016 年 2 月 4 日
any better and efficient way to do this.
if true
XY = zeros(len_x,2);
xrest = zeros(numData-1,len_x);
yrest = zeros(numData-1,len_x);
dist_mat =zeros(len_x,numData-1);
XY = [ns(1).x',ns(1).y'];
for k = 2:numData
xrest(k,:) = ns(k).x;
yrest(k,:) = ns(k).y;
xrest = xrest';
yrest = yrest';
dist_mat(:,k) = sqrt((xrest(:,k)-XY(:,1)).^2+(yrest(:,k)-XY(:,2)).^2);
end
end
Brendan Hamm
Brendan Hamm 2016 年 2 月 4 日
You are trying to assign to a scalar element of distance_nhood an entire vector and this is a dimension mismatch. The reason for this is that tx and ty are both vectors and not the first node.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics and Visualization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by