Add 3 trendlines in a scatterplot figure

5 ビュー (過去 30 日間)
SANDRA COSTA
SANDRA COSTA 2020 年 5 月 3 日
コメント済み: SANDRA COSTA 2020 年 5 月 5 日
I have 3 data sets for y and 1 data set for x and I would like to do a scatterplot with 3 trendlines. I was able to create the scatterplots but I dont know how to add a trendline for each data set to my figure. I have tried the basic fitting tool but when I try to add the trendline to the second set of data, the first trendline disappears and I need all three trendlines in the figure.
Here is my code:
%% Load data
dataset=xlsread('sediment_matlab.xls','Sheet1','A1:F14')
Time=dataset(:,1);
A=dataset(:,2);
B=dataset(:,4);
C=dataset(:,6)
scatter(Time,A),xlabel('Time(hours)'),ylabel('[NO3-]'); hold on; scatter (Time,B); hold on; scatter(Time,C)
ttl = sprintf('[Light NO3-]');
title(ttl,'FontWeight','bold', 'FontSize',12, 'FontName','Times New Roman');
  2 件のコメント
Image Analyst
Image Analyst 2020 年 5 月 3 日
You forgot to attach 'sediment_matlab.xls'. And I see no trends in your data, much less 3 trends. Can you indicate where you see trends? Do you want some kind of curve plotted vs. time, like a quadratic or something for each trend???
SANDRA COSTA
SANDRA COSTA 2020 年 5 月 3 日
I just wanted to add 3 trendlines for each data set just like this graph.

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

回答 (1 件)

darova
darova 2020 年 5 月 4 日
Use polyfit
a1 = polyfit(Time,A,1);
A1 = polyval(a1,Time);
plot(Time,A1)
  1 件のコメント
SANDRA COSTA
SANDRA COSTA 2020 年 5 月 5 日
Perfect. Thank you so much.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by