Plot several series in the same chart
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello
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!
Alex
0 Commenti
Risposte (2)
Isktaine
il 8 Ago 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
plot(X,Y1)
%Keep the axis and data
hold on
%Removes first 5 elements of x where there's no corresponding Y data
smaller_x=x(6:end)
%Plot Y2 data, 95 points against a new X vector
plot(smaller_x,Y2)
%turn off hold so you can create new plots
hold off
Does this make sense?
0 Commenti
Matt Fig
il 8 Ago 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];
plot(x,y1,'r',x,y2p,'b')
0 Commenti
Vedere anche
Categorie
Scopri di più su Bar Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!