Extending regression lines beyond data span

Hi everyone,
I'm working on a code that would predict Arctic ice coverage during the rest of the 21st century, like so:
%load ice coverage data
data = load('Ice_North.txt');
%define variables
year = data(:,1);
data_month(:,1:12) = data(:,2:13); %a new matrix with monthly values only
%calculate the yearly average time series
yearData = nanmean(data_month,2);
%plot yearly averaged time series
figure(1)
plot(year, yearData, 'LineWidth',2,'Color','b')
xlabel('Year')
ylabel('Sea ice coverage (milions of km^2)')
grid on
title('Annual average Arctic sea ice coverage')
%regression analysis
%linear
coeff1 = polyfit(year,yearData,1);
f1 = polyval(coeff1,year);
hold on
plot(year,f1,'LineWidth',1.5,'Color','r')
%quadratic
coeff2 = polyfit(year,yearData,2);
f2 = polyval(coeff2,year);
hold on
plot(year,f2,'LineWidth',1.5,'Color','g')
legend('Data','Linear interpolation','Quadratic interpolation')
I would like to extend both linear and quadratic interpolations, so that they reach up to, for example 2100. Any advice on how to do that?
All the best,
Maja

댓글 수: 5

Jonas
Jonas 2021년 4월 27일
just add the numbers you asked for to the year variable in the polyval function, it evaluates the regression model at the point you enter there
Thanks a lot!
Scott MacKenzie
Scott MacKenzie 2021년 5월 8일
편집: Scott MacKenzie 2021년 5월 8일
I made the modification Jona suggested. Seems the model predicts 2066 as the year all the sea ice is gone.
Maja, may I ask: Where did you get this data?
Hi Scott,
Data is from the National Snow and Ice Data Center:
https://nsidc.org/data/g02135
Great. Thanks very much. Very nice work.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

질문:

2021년 4월 27일

댓글:

2021년 5월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by