Finding correlation between two row matrices

조회 수: 2 (최근 30일)
Reem Almehairbi
Reem Almehairbi 2021년 12월 5일
답변: Abolfazl Chaman Motlagh 2021년 12월 5일
I have two 1* 6 matrices x and y. I'd like to find the correlation between them. when I use
correlation_coefficients=corrcoef(x,y)
I get a 2*2 matrix with all absolute values close to one. This implies that the relationship between the two variables is a linear relationship. However, the graph obtained when plotting the two variables is that of an exponential decay.
I don't know what I'm doing wrong and are there any alternative codes if the one I'm using is not suitable?
P.s. I'm investigating wither the relationship is linear or not (from the graph it is clearly not) How can I find the R-squared value for such data sets?

답변 (1개)

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh 2021년 12월 5일
Use fitlm function. it report you the R-squared value. and fit the linear model.
example:
x=1:0.1:10;
y=exp(x);
Fitted_model = fitlm(x,y);
Fitted_model.Rsquared
ans = struct with fields:
Ordinary: 0.5149 Adjusted: 0.5095
plot(x,y);hold;plot(x,Fitted_model.feval(x))
Current plot held

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by