Filter löschen
Filter löschen

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

31 Ansichten (letzte 30 Tage)
%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

Akzeptierte Antwort

Athul Prakash
Athul Prakash am 21 Nov. 2019
Dynamically changing variable names is not advised, I think you should try storing the data in multiple different tables.
  3 Kommentare
Walter Roberson
Walter Roberson am 1 Jul. 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 am 21 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Tables 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