Naming tables inside a for loop

13 次查看(过去 30 天)
Ahmad
Ahmad 2022-10-10
编辑: Jan 2022-10-10
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?

采纳的回答

Jan
Jan 2022-10-10
编辑:Jan 2022-10-10
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by