How to save multiple Tables in Workspace with different names

조회 수: 15 (최근 30일)
Felix Forrer
Felix Forrer 2021년 5월 9일
댓글: Felix Forrer 2021년 5월 9일
First of all I know i should not be doing this as every answer ist something like "you should use indexing" but i need it.
So, i got hundreds of tables with over 100'000 rows of data in 37 Variables and i have to import them (.csv files) into matlab. I wanted to use a for loop to do this. As the question stated i am not able to get the table saved into my workspace as the table name is not dynamically. Is there any good solution for this? I am not a programmer and i do not have much experience with matlab. What i try is to geht the names for the tables out of "name_cell" and change the "messungen" dynamically with the names i extract from there in some way. I just cannot get this code run. Appreciate every bit of help.
Here is the code i wrote so far:
dinfo = dir('/MATLAB Drive/Nur motor');
names_cell = {dinfo.name}
for i = 3:length(names_cell)
opts = detectImportOptions(names_cell{i});
opts.VariableNamesLine = 11;
opts.DataLines = [12 Inf];
messungen = readtable(names_cell{i},opts);
varname = names_cell{i}
varname = varname(1:end-4)
end
  댓글 수: 5
Stephen23
Stephen23 2021년 5월 9일
편집: Stephen23 2021년 5월 9일
"What i need is to save all the .csv files in seperate tables in my workspace."
The obvious, easy, simple solution is to use indexing, just like the documentation shows:
So far you have not provided any reason why that would not work for you. Something like this:
S = dir('/MATLAB Drive/Nur motor'); % even better: filename/extension matching.
S = S(~[S.isdir]); % correct way to ignore folders (your approach is buggy).
for k = 1:numel(S)
opts = detectImportOptions(S(k).name);
opts.VariableNamesLine = 11;
opts.DataLines = [12 Inf];
S(k).data = readtable(S(k).name,opts);
end
This will be much simpler and more efficient than your approach of saving multiple tables "with different names".
Felix Forrer
Felix Forrer 2021년 5월 9일
Thank you very much this worked just fine!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by