dynamic naming of datasets
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
Antworten (2)
Walter Roberson
am 29 Dez. 2015
You can store your datasets as fields in a structure.
Sd = structfun(@struct2datset, S, 'Uniform', 0);
0 Kommentare
Image Analyst
am 29 Dez. 2015
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 Kommentare
Siehe auch
Kategorien
Mehr zu Data Import from MATLAB 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!