Linear fit line for multiple Y-axis

1 visualizzazione (ultimi 30 giorni)
Syed Hussain
Syed Hussain il 7 Lug 2020
Risposto: dpb il 8 Lug 2020
I need to plot the best fit linear line for multiple y-axis data. I am able to do this with single y-axis but do not know it for multiple y-axes scenario.
(Here is the graph which i want to plot, but the best fit linear line in it, is corresponding to only single y-axis data.)

Risposta accettata

dpb
dpb il 8 Lug 2020
You'll get same coefficients if you fit
b=polyfit(t,mean(y,2)); % assume columns are variables, rows, observations
as will by fitting all data by duplicating the time vector for all columns and fitting all observations individually. Statistics will be somewhat different owing to the independent variables, but if all one cares about are the coefficients, the average works and is simpler to code.
x=[1:10].'; % an x-vector
y=rand(10,10); % 10 column vectors to go with x
>> b1=polyfit(x,mean(y,2),1) % fit mean by column
b1 =
0.0178 0.3858
>> b2=polyfit(repmat(x,10,1),y(:),1) % fit all observations individually
b2 =
0.0178 0.3858
>>
As can see, one gets same coefficient array either way -- altho in reality it's not that much more to "do it right".

Più risposte (0)

Categorie

Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by