Can't plot a trendline

8 ビュー (過去 30 日間)
Carter Squires
Carter Squires 2018 年 12 月 3 日
回答済み: Chad Greene 2019 年 3 月 4 日
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 日
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 日
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)

カテゴリ

Help Center および File ExchangeDescriptive Statistics and Visualization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by