Selecting unique tracks to plot multiple lines in a figure?

조회 수: 6 (최근 30일)
Jaclyn
Jaclyn 2013년 7월 30일
I have a dataset of tracks and associated (x,y) points which are identified by a track ID, for ex.:
trackID, X, Y
1 45 75
1 50 80
1 55 85
3 10 30
3 15 35
I need to plot all these tracks (which all vary in number of points) on the same figure as individual lines. So far all I have is each track ID, is there a way to loop through and pull out each track's coordinates to put in a single plot?
[trackID,ia,ic] = unique(ds(:,1));
The dataset has 45000 points and I'm using Matlab 2011.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 30일
편집: Azzi Abdelmalek 2013년 7월 30일
c1=A(:,1);
idx=unique(c1);
n=numel(idx);
c=cell(n,1);
for k=1:n
c{k}=A(A(:,1)==idx(k),2:3);
end
c{1}
c{2}

추가 답변 (1개)

dpb
dpb 2013년 7월 30일
The loop solution...
u=unique(ds(:,1));
ix=u(1)==ds(:,1); % find first set locations
plot(ds(ix,2),ds(ix,3)) % plot them
hold on % prep for remaining
for i=2:length(u) % rest
ix=u(i)==ds(:,1);
plot(ds(ix,2),ds(ix,3))
end
Likely want to modify line colors, add legends, etc., but that's the gist of it...

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by