How to view the index of a line (or set of connected lines) in a plot?
조회 수: 6 (최근 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 ?
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Point Cloud Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!