In Matlab I have a 2x1000 matrix of x, y coordinates called set. I have created
ID: 3598850 • Letter: I
Question
In Matlab
I have a 2x1000 matrix of x, y coordinates called set. I have created a new 1000x1000 matrix of distances from every x,y coordinate to every other x, y coordinate. Column 1 has all the distances of the first x,y node to the next 999 nodes in row 1 - 1000. Same for column 2...column1000. I need a way to check if the value in the rows is < 100 for each individual column and if it is plot a line between the two x,y coordinates. Please look at this image for my code: https://i.imgur.com/rYrL88y.png
Explanation / Answer
set1 = rand(1,1000)*1000;
set2 = rand(1,1000)*1000;
set = [set1' set2'];
t=1;
[m n] = size(set);
size(set);
dist = zeros(m,n);
for i =1:m
for j = 1:n
dist(i,j) = sqrt((set(i,1)-set(j,1))^2 +(set(i,2)-set(j,2))^2);
%track the coordinate that gives distance less than 100 and plot
%the line between two coordinates
if(dist(i,j)<100)
x1(t) = set(i,1); %save the coordinate od x1,y1
y1(t) = set(j,1)
x(t)=set(j,1); %save the coordinates of x2,y2
y(t)=set(j,2);
t=t+1;
end
end
end
plot([x1 y1],[x y]) %plot line between two point having distance less 100
%plot(x,y) %plot all the points that have distance less than 100
t %no.of elements having value less than 100 in set
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.