How to view the index of a line (or set of connected lines) in a plot?

5 次查看(过去 30 天)
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 ?

采纳的回答

KSSV
KSSV 2019-7-3
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))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Point Cloud Processing 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by