How to find distance between different points in a dataset as shown in scatter plot
1 次查看(过去 30 天)
显示 更早的评论
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153981/image.png)
4 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!