Clear Filters
Clear Filters

How to skip the particular year while writing a code?

1 view (last 30 days)
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 Comments
Adam
Adam on 1 Jun 2017
Edited: Adam on 1 Jun 2017
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 on 1 Jun 2017
Edited: Walter Roberson on 1 Jun 2017
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

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Jun 2017
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

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!