How do you plot with missing data?

5 vues (au cours des 30 derniers jours)
econogist
econogist le 8 Avr 2022
Modifié(e) : Voss le 8 Avr 2022
Suppose I have three vectors: Year=[2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010], X=[1 2 1 4 5 6 7 2 3 5 6], and Y=[1 2 3 4 5 2 3 1 2 3].
I want to plot them on the same graph where 'Year' is on the x-axis. Because the third term in 'Y' is missing data, how do I go about plotting this? Ideally, I'd like the line plot to be disjointed where data is missing.

Réponse acceptée

Voss
Voss le 8 Avr 2022
Modifié(e) : Voss le 8 Avr 2022
If you know where the missing element(s) belong(s), put NaN(s) there, which will give you a disjointed line:
Year = [2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010];
X = [1 2 1 4 5 6 7 2 3 5 6];
% this:
Y = [1 2 NaN 3 4 5 2 3 1 2 3];
% or this:
Y = [1 2 3 4 5 2 3 1 2 3];
Y = [Y([1 2]) NaN Y(3:end)];
plot(Year,[X;Y])
legend('X','Y')

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by