dynamic naming of datasets
3 次查看(过去 30 天)
显示 更早的评论
Hi,
Long story short my script uploads into MATLAB a number of Excel files, using a for cycle, and saves them in the following way:
S is a structure, it's fields are A1 A2 ... and they are also structures (I shall call them substructures from now on, they are one for every excel file I upload). The fields of these substructures are say x, y, z (3 cell arrays). The way my function works A1, A2, ... are name dynamically depending on the date of the file I'm uploading (I have one for every date, think like H151221 H151222 and so on), while the substructure's fields are always the same (defined by the uploading function, so I'll have H151221.z H152122.z etc.).
What I would also like to do is to save S.H151221.z as a dataset using cell2dataset or struct2datset. My big problem lies in the fact that I cannot create a dynamically named dataset that will allow me to call it say Dat_H151221.
Any hints? I know dynamic variable creation is shamed upon but I can't see any way around it since I'm uploading 100 different files and need a dataset for each of them.
Thanks!
回答(2 个)
Walter Roberson
2015-12-29
You can store your datasets as fields in a structure.
Sd = structfun(@struct2datset, S, 'Uniform', 0);
0 个评论
Image Analyst
2015-12-29
I agree with Walter - you should use a table. In fact it's pretty easy to just load your Excel file into a table immediately upon importing:
for k = 1 : numberOfFiles
thisFileName = fullfile(.............
t(k) = readtable(thisFileName; % Instead of xlsread() use readtable()
end
Then if you want to save your array of tables, just use save()
save('MyExcelTables.mat', t't';
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!