Plotting the trend line without plotting the data

11 ビュー (過去 30 日間)
Sophia
Sophia 2021 年 2 月 8 日
回答済み: Chad Greene 2021 年 3 月 25 日
I am trying to plot the trend line for three year data combined, So basically trend line on top the attached scatter plot.
% stack all three years to plot the trend line
msid_3yr = [icedrift_bg_2007;icedrift_bg_2015;icedrift_bg_2017];
wspd_3yr = [wspd_bg_2007;wspd_bg_2015;wspd_bg_2017];
%If i use the following it replaces the existing scatter plot colour dots
mdl = fitlm(wspd_3yr,msid_3yr,'linear')
plot(mdl)

採用された回答

KSSV
KSSV 2021 年 2 月 8 日
編集済み: KSSV 2021 年 2 月 8 日
REad about hold on. After plotting the first, use hold on. Alkso you may go ahead like below:
p = polyfit(wspd_3yr,msid_3yr,1)
xi = wspd_3yr ;
yi = polyval(p,wspd_3yr,msid_3yr) ;
hold on
plot(xi,yi,'k')
Also when you use:
mdl = fitlm(wspd_3yr,msid_3yr,'linear') ;
mdl has coefficients of the line, you can use polval like shown above to plot.
  1 件のコメント
Sophia
Sophia 2021 年 2 月 8 日
@KSSV worked like a charm, thank you so much!

サインインしてコメントする。

その他の回答 (1 件)

Chad Greene
Chad Greene 2021 年 3 月 25 日
Or more simply,
polyplot(wspd_3yr,msid_3yr)
using the polyplot function found here.

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by