Can't plot a trendline
3 次查看(过去 30 天)
显示 更早的评论
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
2018-12-3
Well, what can we possibly do? You didn't attach any data - not even a screenshot.
Please read this link
回答(2 个)
Chad Greene
2019-3-4
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!