Naming tables inside a for loop

13 visualizaciones (últimos 30 días)
Ahmad
Ahmad el 10 de Oct. de 2022
Editada: Jan el 10 de Oct. de 2022
I want to change names of tables inside a for loop. Each iteration inside the for loop represent one table.
N=2;
for ii = 1:N
if ii = 1
jj = 'Attendance'
else if ii = 2
jj = 'Absence'
end
Table_'Attendance' = table(variables);
Table_'Absence' = table(variables)
end
end
I want to generate a seperate table at each iteration. I generate same variables at each iteration with different data. That's why I want to put them in tables with different names.
For example, here I mentioned that I want to have two tables and I want to name them "Table_Attendance" and "Table_Absence", respectively. Is there a way to do this?

Respuesta aceptada

Jan
Jan el 10 de Oct. de 2022
Editada: Jan el 10 de Oct. de 2022
This is the most frequently asked question in this forum. The answer is easy: Don't do this. It is a shot in your knee.
Better:
NameList = {'Attendance', 'Absence'};
for ii = 1:2
TableList.(NameList{ii}) = table(variables);
end

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by