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

53 ビュー (過去 30 日間)
Mariana
Mariana 2019 年 11 月 14 日
コメント済み: Hugues 2023 年 12 月 21 日
%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 Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by