fitlm with sequential variable names

조회 수: 4 (최근 30일)
Maria445
Maria445 2017년 10월 17일
I'm trying to run multiple regressions using a for loop. This is my code:
(N is the number of columns in the matrices, each column represents one of the 24 hours. Each matrix is a different variable.)
for i = 1:N
table_hourly = table( First_matrix(:,i), Second_matrix(:,i), Third_matrix(:,i),'VariableNames', ...
{sprintf('Variable1_Hour%d',i) sprintf('Variable2_Hour%d',i) sprintf('Variable3_Hour%d',i)});
a = sprintf('Variable1_Hour%d',i);
b = sprintf('Variable2_Hour%d',i);
c = sprintf('Variable3_Hour%d',i);
fitlm(table_hourly, 'a ~ b + c', 'Intercept',0,'Robust',1)
end
With this code, I can correctly create a table (table_hourly) for each different hour, with the right column headers. However, when it gets to the regression, fitlm fails to recognise the variable names.
How can I solve this problem?

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by