How to view the index of a line (or set of connected lines) in a plot?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tintumon
el 3 de Jul. de 2019
Comentada: Tintumon
el 3 de Jul. de 2019
Suppose, I am plotting the following trajectory (connected lines) data:
% first trajectory data
track(1).x = [1 1 1 2 4 5];
track(1).y = [20 21 23 24 25 25];
% second trajectory data
track(2).x = [34 35 36 37];
track(2).y = [90 92 94 96];
hold on;
%plotting the trajectory
for i=1:length(track)
plot(track(i).x,track(i).y)
end
hold off;
In the above code it would be easy to identify the index of the trajectory (here 1 and 2) looking at the plot.
But, when the length of the variable "track" increases i.e, when there are more number of trajectories, I find it difficult to indetify the index of a random trajectory in the plot.
One possible way might be to create labels and display it. But then, if too may trajectories are there, it would be chaos and labels might not be visible.
My question is based on this: Is there any way to visualize the index of the trajectories in a plot, just like when we place the "data-tip" tool in the plot it would show us the values of the line (ie,co-ordinates), for analysis purpose ?
0 comentarios
Respuesta aceptada
KSSV
el 3 de Jul. de 2019
How about this approach? Click at the point you want to know the label.
% first trajectory data
track(1).x = [1 1 1 2 4 5];
track(1).y = [20 21 23 24 25 25];
track(1).label = 1*ones(1,6) ;
% second trajectory data
track(2).x = [34 35 36 37];
track(2).y = [90 92 94 96];
track(2).label = 2*ones(1,4) ;
hold on;
%plotting the trajectory
for i=1:length(track)
plot(track(i).x,track(i).y)
end
hold off;
%% Pick a point
[ptx,pty] = getpts() ;
x = [track(:).x]' ;
y = [track(:).y]' ;
l = [track(:).label]';
%
F = scatteredInterpolant(x,y,l) ;
li = round(F(ptx,pty)) ;
text(ptx,pty,num2str(li))
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!