如何更改数据以使图形中断

时间:2014-01-05 09:38:17

标签: matlab graph

我想用excel构建如下图: enter image description here

我已使用以下行将数据输入matlab:

year = [1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1992 1992 1993 1994 1995 1996 1997 1998 2000 2001 2002 2003 2004 2004 2006 2007 2008 2009 2010 ]

fix_No = [-9.449167466 -11.19432509 -8.500517848 -5.644813211 -2.608063866 2.614370892 6.461752833 7.035549084 8.542521755 12.11070577 6.476900841 8.029225388 4.315820526 4.165349512 5.34593031 7.510812752 -2.629044124 -5.713139529 -8.626773532 -11.83226415。 -8.821345246 -6.396197293 -5.187823611 -1.79008821 3.34099288 5.545228048 7.013763711 6.580524638 4.256524275 ]

fix_No_and_mean = [11.1610424 5.437315474 5.833032482 4.591658232 1.578021362 -1.572756298 -1.03351595 -2.250991302 -3.222969261 -5.734621837。 12.96685642 10.95095066 10.2207684 5.654017602 1.753259697 -2.596143576 -7.155087995 -9.687001589 -8.700979283 -4.290434459。 2.299711172 1.640802028 1.714407543 0.8360893 -0.425484303 -1.160053823 -0.858530711 0.123787867 0.782208621 ]

在1985年和1996年,应该像excel图中那样中断线。但是我怎么能用Matlab做到这一点?我放了一个“。” (点)中断应该是,但matlab不接受点。 构建图形的线条如下所示:

plot(year,fix_No, 'color', 'k', 'LineWidth',2, 'LineSmoothing','on')
line(year,fix_No_and_mean, 'color', 'r', 'LineWidth',2, 'LineSmoothing','on')
xlabel('year')
legend('fixed number', 'fixed number')

1 个答案:

答案 0 :(得分:4)

你应该把“NaN”代替“。” ,即。在对应于1985年和1996年的向量fix_No_and_meanfix_No上的位置,放置NaN

这将绘制不同的行,如您从excel附加的图中所示。