Trouble with a correlation analysis code

조회 수: 2 (최근 30일)
Alexandra Brian
Alexandra Brian 2017년 1월 28일
편집: John Chilleri 2017년 2월 1일
I'm writing a code to run a correlation analysis between two variables under certain conditions. I want to see if there is a correlation between the second column and the first if the second's value is greater than 0. I wrote the following code, but MATLAB continues to print the error, "Index exceeds matrix dimensions".
clear all
indicators = xlsread('largedata1.xlsx');
X = xlsread('largedata1.xlsx', 1, 'A:A');
rows = indicators(:,2)>0; %Logical vector with the rows which satisfy all conditions.
if any(rows) % True if there is at least 1 row which meats the condition.
md1 = fitlm(indicators(rows, [2]), X(rows)); % Fit with the rows which satisfy condition.
end
Can you please help?
Best, A
  댓글 수: 2
Image Analyst
Image Analyst 2017년 1월 28일
Can you attach 'largedata.xlsx' so people can try your code?
Alexandra Brian
Alexandra Brian 2017년 1월 29일
I added it! Thanks for the suggestion.

댓글을 달려면 로그인하십시오.

채택된 답변

John Chilleri
John Chilleri 2017년 1월 28일
편집: John Chilleri 2017년 2월 1일
Hello,
I downloaded your data and ran your code and it didn't encounter any errors for me (rows was a logical vector so rows==1 actually isn't needed like I suggested - I was testing with a double vector).
clear all
indicators = xlsread('largedata1.xlsx');
X = xlsread('largedata1.xlsx', 1, 'A:A');
rows = indicators(:,2)>0; %Logical vector with the rows which satisfy all conditions.
if any(rows) % True if there is at least 1 row which meats the condition.
md1 = fitlm(indicators(rows, [2]), X(rows)); % Fit with the rows which satisfy condition.
end
>> md1
md1 =
Linear regression model:
y ~ 1 + x1
Estimated Coefficients:
Estimate SE tStat pValue
________ _________ ______ __________
(Intercept) 0.056209 0.0049663 11.318 4.6459e-28
x1 0.18966 0.10075 1.8825 0.060056
Number of observations: 1022, Error degrees of freedom: 1020
Root Mean Squared Error: 0.12
R-squared: 0.00346, Adjusted R-Squared 0.00249
F-statistic vs. constant model: 3.54, p-value = 0.0601
  댓글 수: 3
Alexandra Brian
Alexandra Brian 2017년 1월 31일
Thanks John!
John Chilleri
John Chilleri 2017년 2월 1일
Changed solution, but it doesn't help you it would seem.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Repeated Measures and MANOVA에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by