How to skip the particular year while writing a code?

1 次查看(过去 30 天)
I have data from 1980 to 2016, and i want to skip year 1992 from this. such that,the trend i am making from the command written below won't include year 1992 and its value.
B=[1980:2016 ],
C = [[0.0641771801575756 ,0.0705314239372543 ,0.169254911748342 ,0.0990499637351591 ,0.0824609982128868 ,0.0727823998431182 ,0.0751631840007672 ,0.0710952435222895 ,0.0716510334748713 ,0.0736190018376645 ,0.0721885991163370 ,0.256978377948127 ,0.129986763409104 ,0.0987830309715417 ,0.0859226479389245 ,0.0796368312126925 ,0.0795688352738768 ,0.120342752230900 ,0.0791018172841989 ,0.0773716181241581 ,0.108283337216576 ,0.108465660032082 ,0.115652007379638 ,0.114943930535510 ,0.128375015353833 ,0.116685880909142 ,0.138821961329473 ,0.133736439249935 ,0.139184962383231 ,0.133372815856175 ,0.133362557160868 ,0.143481889370999 ,0.135834567871762 ,0.133126726127365 ,0.149047349058725 ,0.156772003348878 ,0.148213197724466]],
Bi = linspace(min(B), max(B)),
trend_line = interp1(B, C, Bi, 'spline'),
figure(1)
plot(B,C,'pg', Bi,trend_line,'-r')
grid
  2 个评论
Adam
Adam 2017-6-1
编辑:Adam 2017-6-1
You seem to be interpolating onto an arbitrary grid so 1992 is not explicitly included anyway. You should just be able to replace the corresponding C value with a Null though.
Pritha Pande
Pritha Pande 2017-6-1
编辑:Walter Roberson 2017-6-1
ok, maybe in the above example i can do it without much efforts But, how to do it in the example presented below?
years = 1980:2016;
for i=1:80
for j=1:80
p = polyfit(years, reshape(seasonal_JJA(i, j, :), 1, []),1);
slopes(i, j) = p(1);
end
end

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-6-1
B=[1980:2016 ]
mask = ~ismember(B, 1992);
C = [[0.0641771801575756 ,0.0705314239372543 ,0.169254911748342 ,0.0990499637351591 ,0.0824609982128868 ,0.0727823998431182 ,0.0751631840007672 ,0.0710952435222895 ,0.0716510334748713 ,0.0736190018376645 ,0.0721885991163370 ,0.256978377948127 ,0.129986763409104 ,0.0987830309715417 ,0.0859226479389245 ,0.0796368312126925 ,0.0795688352738768 ,0.120342752230900 ,0.0791018172841989 ,0.0773716181241581 ,0.108283337216576 ,0.108465660032082 ,0.115652007379638 ,0.114943930535510 ,0.128375015353833 ,0.116685880909142 ,0.138821961329473 ,0.133736439249935 ,0.139184962383231 ,0.133372815856175 ,0.133362557160868 ,0.143481889370999 ,0.135834567871762 ,0.133126726127365 ,0.149047349058725 ,0.156772003348878 ,0.148213197724466]],
Bi = linspace(min(B), max(B)),
trend_line = interp1(B(mask), C(mask), Bi, 'spline'),
figure(1)
plot(B(mask),C(mask),'pg', Bi,trend_line,'-r')
grid

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Splines 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by