I'm trying to plot a least squares trendline to a scatterplot of data on CO2 concentration versus temperature anomaly. The code is below-- the scatterplot is successfully created, but the trendline is not appearing. I'm not getting any error messages from this code. Any help would be appreciated.
%% plot Tanomaly vs. CO2
figure(8)
clf
plot(CO2.value(2:162),IPCC_combined_Tanom(2:162),'r.','markersize',15)
hold on
grid on
xlabel('Global CO2 Concentration (PPMV)')
ylabel('Global Combined T Anomaly °C')
title('Temperaure anomaly vs CO2 Concentration')
set(gca,'fontsize',18)
xlim([280 400])
ylim([-1 1])
for n=1:10:length(CO2.value)
text(CO2.value(n),IPCC_combined_Tanom(n),[' \leftarrow ' num2str(year(n))],'fontsize',14)
end
window=axis;
loc=find(~isnan(CO2.value(2:162)) & ~isnan(IPCC_combined_Tanom(2:162)));
A=[CO2.value(loc) ones(length(loc),1)];
m=A\IPCC_combined_Tanom(loc);
plot(window(1:2),m(1)*window(1:2)+m(2),'k-','linewidth',2)
disp(['Climate sensitivity: ' num2str(round(m(1),5)) ' °C/PPMV CO2'])

댓글 수: 1

Image Analyst
Image Analyst 2018년 12월 3일
Well, what can we possibly do? You didn't attach any data - not even a screenshot.

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

답변 (2개)

Star Strider
Star Strider 2018년 12월 3일

0 개 추천

I can’t see that you invited the trendline to appear.
See the documentation on lsline (link) to invite it to participate.
Chad Greene
Chad Greene 2019년 3월 4일

0 개 추천

Check out the polyplot function in the Climate Data Toolbox. If you define the x and y data, plotting a least-squares trend line is just
polyplot(x,y)

카테고리

도움말 센터File Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기

질문:

2018년 12월 3일

답변:

2019년 3월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by