Change the name of a table located in my workspace inside a for loop

56 visualizaciones (últimos 30 días)
%Data Folder Analysis
file = dir(fullfile('C:\Users\Desktop\data','*mat'));
num_files=sprintf('The following mat files are to be analyzed: %d',length(file));
%Amount of files analyzed
for i=1:1 %length(file)
current_file = sprintf('Data_set_%d.mat',i);
table_name= table (t,x,y,m)
new_name =sprintf('Table',i);
table_name = new_name;
end
I am trying this but it is not working if the new name that I want to assign is variable.
If I try:
a = table_name;
then the table is saved, but I want to change the name of "a" on evry iteration

Respuesta aceptada

Athul Prakash
Athul Prakash el 21 de Nov. de 2019
Dynamically changing variable names is not advised, I think you should try storing the data in multiple different tables.
  3 comentarios
Walter Roberson
Walter Roberson el 1 de Jul. de 2021
The proper process is not to do it at all.
Do you have a particular context in which you believe that dynamically naming variables is your only choice? If so please describe it. Or is yours just a general question of "Okay, but suppose I wanted to do this?"
The tutorial about why not to do this contains many hints about how it could be done: http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
Hugues
Hugues el 21 de Dic. de 2023
I just want to import files and name them during the program play instead of after. Most of my files are the same big tables of test data.
IE: play the import program, since it is the same type of csv table it should import the same way just with a different name in function of the date or user or else. Once the name is defined the table is stored in my workspace and i can work with other functions on it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by