Linear fit line for multiple Y-axis

1 Ansicht (letzte 30 Tage)
Syed Hussain
Syed Hussain am 7 Jul. 2020
Beantwortet: dpb am 8 Jul. 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.)

Akzeptierte Antwort

dpb
dpb am 8 Jul. 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".

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by