fitlm with sequential variable names

2 次查看(过去 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 中查找有关 Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by