필터 지우기
필터 지우기

Plot several series in the same chart

조회 수: 3 (최근 30일)
Alex
Alex 2012년 8월 8일
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

답변 (2개)

Isktaine
Isktaine 2012년 8월 8일
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?

Matt Fig
Matt Fig 2012년 8월 8일
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')

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by