Clear Filters
Clear Filters

Selecting unique tracks to plot multiple lines in a figure?

1 view (last 30 days)
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.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 30 Jul 2013
Edited: Azzi Abdelmalek on 30 Jul 2013
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}

More Answers (1)

dpb
dpb on 30 Jul 2013
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...

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!