How can i plot the data for specific time intervals?

79 views (last 30 days)
Am trying to plot vehicle trajectories(time-space plots) using following data. I have plotted all the vehicles for whole time duration of 15 minutes.Now I need to Plot it for particular time periods( for e.g.,between 100 sec and 400 sec) for all vehicle numbers in that time interval.How can i select the data only for a particular time interval and plot for all vehicles in a single figure?
Data format: Veh_no 2 2 2 2 2 2 ..3 3 3 3 3 3... 4 4 4 4... time(sec) 0 0.1 0.2 0.3 0.4 0.5 ..0.2 0.3 0.4 0.5 0.6 0.7...0.1 0.2 0.3 0.4 distance(m) 0 0.2 0.5 0.8 0.9...0.3 0.4 0.7 0.9 1.3 1.5...0.2 0.4 0.8 1.1...

Accepted Answer

KSSV
KSSV on 16 Jun 2017
Check the below code:
t =0:0.01:2*pi ;
x = sin(t) ;
plot(t,x)
%%draw data only between 2 and 4
idx = (t>2 & t <=4) ;
hold on
plot(t(idx),x(idx),'.r')
You can get logicals of the indices which you want to plot, and use these logical indices for plotting.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!