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

56 次查看(过去 30 天)
%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

采纳的回答

Athul Prakash
Athul Prakash 2019-11-21
Dynamically changing variable names is not advised, I think you should try storing the data in multiple different tables.
  3 个评论
Walter Roberson
Walter Roberson 2021-7-1
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 2023-12-21
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by