Import multiple data files (.sto) together
18 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sanchana Krishnakumar
il 5 Ago 2020
Commentato: Sanchana Krishnakumar
il 13 Ago 2020
Hi, I'm trying load multiple .sto files together and get data from them to process each of them. I used the following code to import the data, but this stores all of the data into one big struct. However I would need them into sepearate variable names in my workspace. Please help.
files = dir('*.sto');
for i=1:length(files)
filename = files(i).name;
eval('a = importdata (filename)');
out(i) = a;
end
Now the out file looks like the following image. I would like to have each of this 2560x7 data as the respective original filenames before the import in my workspace.
The files variable in the code contains all the names of the original files that are being imported. Is there a way to use the file varaible to store each value respectively instead of using out(i) and storing all of them together.
Thanks in advance. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/342079/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/342079/image.png)
0 Commenti
Risposta accettata
Gaurav Garg
il 10 Ago 2020
Hi Sanchana,
filename = genvarname ( files(i).name, who) ;
should give you a unique variable name for each file.
Più risposte (1)
Nipun Katyal
il 10 Ago 2020
Although it is recommended not to allot variable names dynamically and it is better to access similar files using data stores, if you need to assign the variable names as file names this is how you can do it,
files = dir('*.sto');
for i=1:length(files)
% genvarname creates a legal identifier from the given string, here filename.
v = genvarname(files(i).name);
eval([ v ' = importdata (files(i).name)']);
end
Vedere anche
Categorie
Scopri di più su HDF5 in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!