Selecting unique tracks to plot multiple lines in a figure?

3 次查看(过去 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 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by