Naming tables inside a for loop

13 Ansichten (letzte 30 Tage)
Ahmad
Ahmad am 10 Okt. 2022
Bearbeitet: Jan am 10 Okt. 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?

Akzeptierte Antwort

Jan
Jan am 10 Okt. 2022
Bearbeitet: Jan am 10 Okt. 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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by