Plot several series in the same chart
2 views (last 30 days)
Let's say I have a date vector X of length 100 that I want to use as x-axis in my plot. I also have another vector Y of length 100. I can thus plot Y as a function of X. I also have third vector Y2 which I want to plot on the same chart. The problem is that the length of Y2 is smaller, say 95, because there are no observations on the first 5 days. So, I want to make a plot where I plot Y and Y2, so that Y2 starts later (at X5).
How can I do this? Thank you very much for your time and consideration!
Isktaine on 8 Aug 2012
You can still plot them on the same graph, you just need to make your x vector smaller. For example
%Plot your first 100 points
%Keep the axis and data
%Removes first 5 elements of x where there's no corresponding Y data
%Plot Y2 data, 95 points against a new X vector
%turn off hold so you can create new plots
Does this make sense?
Matt Fig on 8 Aug 2012
You can pad with nans to stand for no observation. For example:
% Let's create some data. Say this data is the given:
x = 1:10;
y1 = x.^2;
y2 = (6:10).^2.1;
% Note that y2 does not have observations for 1:5. So we pad it:
y2p = [nan(1,5) y2];