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

3 ビュー (過去 30 日間)
Meshooo
Meshooo 2020 年 11 月 26 日
コメント済み: Meshooo 2020 年 12 月 21 日
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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 26 日
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 件のコメント
Mustafa Sami
Mustafa Sami 2020 年 12 月 15 日
Thank you very much Ameer.
Is there any range (maximum and minimum) for eA.normr?
Meshooo
Meshooo 2020 年 12 月 21 日
Thank you Ameer.

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

その他の回答 (1 件)

KSSV
KSSV 2020 年 11 月 26 日
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)) ;

Community Treasure Hunt

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

Start Hunting!

Translated by