필터 지우기
필터 지우기

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

조회 수: 9 (최근 30일)
Tintumon
Tintumon 2019년 7월 3일
댓글: Tintumon 2019년 7월 3일
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에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by