www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/PlotTwoTimeSeriesObjectsOnTheSameAxesExample.m
%% Plot Two Time Series Objects on the Same Axes % Create two time series objects from traffic count data, and then plot % them in sequence on the same axes. Add an event to one series, which is % automatically displayed with a red marker. % Copyright 2015 The MathWorks, Inc. load count.dat; count1 = timeseries(count(:,1),1:24); count1.Name = 'Oak St. Traffic Count'; count1.TimeInfo.Units = 'hours'; plot(count1,':b') grid on %% % Obtain time of maximum value and add it as an event: [~,index] = max(count1.Data); max_event = tsdata.event('peak',count1.Time(index)); max_event.Units = 'hours'; %%% % Add the event to the time series: count1 = addevent(count1,max_event); %%% % Replace plot with new one showing the event: plot(count1,'.-b') grid on %% % Make a new time series object from column 2 of the same data source: count2 = timeseries(count(:,2),1:24); count2.Name = 'Maple St. Traffic Count'; count2.TimeInfo.Units = 'Hours'; %%% % Turn hold on to add the new data to the plot: hold on %%% % The plot method does not add labels to a held plot. % Use property/value pairs to customize markers: plot(count2,'s-m','MarkerSize',6), %% % Labels are erased, so generate them manually: title('Time Series: Oak Street and Maple Street') xlabel('Hour of day') ylabel('Vehicle count') %%% % Add a legend in the upper left: legend('Oak St.','Maple St.','Location','northwest')