Linear fit between two sets of independent variables

Hi,
Considering two independent data vectors, for example:
x = [ 1.2500 2.4300 0.7400 2.4300 1.1700 0.5600 0.5300 1.2500 1.9100 1.2600];
y = [-3.4000 -2.0000 -1.9000 -2.0000 -2.9500 -2.7000 -3.1000 -3.4000 -3.4000 -0.4500];
I'd like to find the line that best fits the scatter plot of the two independent data vectors x & y.
At first, I was using 'polyfit', but it seems to consider the inputs as dependent variables.
I've been looking for hours on forums, etc., but couldn't find any solution. Maybe I didn't look with the proper keywords, and there is a very simple solution, or an already existing Matlab function.
Thanks in advance.
Lewis

4 件のコメント

Amit
Amit 2014 年 1 月 16 日
Is there a equation in mind? What do you mean independent data?
Lewis Schardong
Lewis Schardong 2014 年 1 月 16 日
I mean they are two datasets measured differently, with two different methods, and I'd still like to quantify how much they are alike. I hope this is helpful!
Amit
Amit 2014 年 1 月 16 日
From your statement, (tell me if I am correct), you have two data sets measured for the same purpose using two different methods. So are they suppose to (nearly) same (y=x)? and you trying to find a correlation like R^2 value for these?
Lewis Schardong
Lewis Schardong 2014 年 1 月 16 日
yes exactly!

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

回答 (2 件)

Amit
Amit 2014 年 1 月 16 日

0 投票

If your model if y = x; Then,
m = mean(y);
J = sum((x-y).^2);
S = sum((y-m).^2);
r2 = 1 - (J/S); % R^2 value or correlation of fit

4 件のコメント

Amit
Amit 2014 年 1 月 16 日
However, looking at your data, I dont think they are very well correlated. x is positive, while y data are all negative.
Lewis Schardong
Lewis Schardong 2014 年 1 月 16 日
that was just subsamples of the whole datasets. the datasets usually contain more than 500 data points that I did not paste here obviously! but I would like is to get the a,b coefficients of a y=ax+b line...
Amit
Amit 2014 年 1 月 16 日
try a = polyfit(x,y,1)
Lewis Schardong
Lewis Schardong 2014 年 1 月 16 日
that's what I did, but I'd like to mimize both x & y at the same time!

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

Lewis Schardong
Lewis Schardong 2014 年 1 月 16 日

0 投票

I apologize if that was unclear. Basically, what I want to do is find the line that best fits two data vectors by minimizing the distance between the line and both x and y coordinates. There may be a Matlab function that can do this, I might just haven't found it yet. Thanks again.

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

質問済み:

2014 年 1 月 16 日

回答済み:

2014 年 1 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by