fitlm with sequential variable names

5 visualizaciones (últimos 30 días)
Maria445
Maria445 el 17 de Oct. de 2017
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?

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by