How to know which plot is more linear then the other?

4 visualizzazioni (ultimi 30 giorni)
Dear all,
I have two datasets arrays:
A = [0
0.423891532
0.819380304
1.289479809
1.739548357
2.288748183
2.8990623
3.618974647
4.402757506
5.268816221
6.240886445
7.278958674
8.321358342
9.369407383
10.37825178
11.17417756
12.02774088
12.69808163
13.49653247
14.36958724
15.50198578
16.68295148
20.09421834]
%%
B = [0
0.406558949
0.771247013
1.123943155
1.487752056
1.915016538
2.365427777
2.852526752
3.419995212
3.933726314
4.436914792
4.958793052
5.510476759
5.961517074
6.415268974
6.843890692
7.102927349
7.118216122
7.677116245
8.751585797
9.636923065
10.32502819
12.9488068]
%%
plot(A, 'green')
hold on
plot(B, 'blue')
hold off
%%
Both A and B are nonlinear curves, but B seems to be more linear (less curvature) than A.
How can I show such information numerically?
Any sugguestion will be appreciated.
Best,
Meshoo

Risposta accettata

Ameer Hamza
Ameer Hamza il 26 Nov 2020
You can see the residual error with linear fit to see which dataset is more linear
[~, eA] = polyfit(1:numel(A), A, 1)
[~, eB] = polyfit(1:numel(B), B, 1)
Result
>> eA.normr
ans =
4.0713
>> eB.normr
ans =
2.8868
Vector 'B' is more linear as compared to A.
  2 Commenti
Mustafa Sami
Mustafa Sami il 15 Dic 2020
Thank you very much Ameer.
Is there any range (maximum and minimum) for eA.normr?

Accedi per commentare.

Più risposte (1)

KSSV
KSSV il 26 Nov 2020
How about finding the area bounded by the curves..which ever has least area is straight.
A = [0
0.423891532
0.819380304
1.289479809
1.739548357
2.288748183
2.8990623
3.618974647
4.402757506
5.268816221
6.240886445
7.278958674
8.321358342
9.369407383
10.37825178
11.17417756
12.02774088
12.69808163
13.49653247
14.36958724
15.50198578
16.68295148
20.09421834]
%%
B = [0
0.406558949
0.771247013
1.123943155
1.487752056
1.915016538
2.365427777
2.852526752
3.419995212
3.933726314
4.436914792
4.958793052
5.510476759
5.961517074
6.415268974
6.843890692
7.102927349
7.118216122
7.677116245
8.751585797
9.636923065
10.32502819
12.9488068]
%%
plot(1:length(A),A, 'g')
hold on
plot(1:length(B),B, 'b')
%%
x = [1:length(A)]' ;
L1 = [[x ; x(1)] [A ;A(1)]] ;
L2 = [[x ;x(1)] [B;B(1)]] ;
patch(L1(:,1),L1(:,2),'r')
hold on
patch(L2(:,1),L2(:,2),'b')
A1 = polyarea(L1(:,1),L1(:,2)) ;
A2 = polyarea(L2(:,1),L2(:,2)) ;

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