How to connect points in a dynamic figure
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Hi,
I am working on a project that dynamically scans and plots new points to a chart. I need to connect the points that fit specific criteria.
E.g, when the distance between any pair of points is less than or equal to 2, the two points are connected. Now points (0,0) and (0,4) are plotted already. If the next scanned point is (2,0), how shall I connect the point with the other two?
Thanks in advance! :)
1 Commento
Risposte (1)
  Daksh
    
 il 2 Feb 2023
        I understand that you wish to connect pairs of dynamically added points with a line to a given plot figure if the Euclidean distance between the added point and any existing points is <=2. 
Kindly refer to the code below: 
% plotting the original graph 
x=[0 0; 0 4]; 
hold on 
for i=1:length(x) 
    plot(x(i,1),x(i,2), 'or') 
end
Now let's assume we dynamically create a new point (0,2) and store it to variable 'y' in workspace, and now we want to connect point y to all existing points in the graph with pairwise Euclidean distance <=2. This is how it can be done: 
% New point added
y=[0,2]; 
x1=y(1); 
y1=y(2); 
plot(x1,y1, 'ob') 
for i=1:length(x) 
    x2=x(i,1); 
    y2=x(i,2); 
    if(sqrt((x1-x2)^2 + (y1-y2)^2) <=2) 
        plot([x1,x2], [y1,y2], 'b-', 'LineWidth', 2); 
    end 
    x(length(x)+1,1)=x1; 
    x(length(x)+1,2)=y1; 
end 
hold off 
Hope it helps! 
0 Commenti
Vedere anche
Categorie
				Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



