简体   繁体   中英

Plot two time series in one figure(MATLAB)

Suppose that we have these two series:

First_Series = [1, 1200; 2,1300; 3,100; 5,267;  6,2674; 7,1346];
Second_Series = [8, 1340; 9,2100; 10,1100];

In both series first column is x-axis and second column is y-axis. I want these two series in a same line-plot with different colors.

  1. Call figure ; This creates a window to plot the graph
  2. Call plot on the first one, this will plot the first series
  3. Issue the command hold on; this holds the previously plotted graph window
  4. Plot the second series--it will plot on the held graph

When you issue the command hold off; it will release the graph window. New plots will go to a new graph window.

Here's an example with your data set plotting red and green lines for the two series:

 figure;
 plot(First_Series(:,1), First_Series(:,2), 'r');
 hold on;
 plot(Second_Series(:,1), Second_Series(:,2), 'g');
 hold off;

You should get the following result: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM