Loading and saving sequence of files?
Mostrar comentarios más antiguos
Hello. I have number of .mat files in a same directory that has a pattern SSR(Year)(Month)(Day). The problem is not every date is included in my files. The first three files out of 55 files are as follows.
SSR20140103.mat
SSR20140207.mat % All of the files have same variable name (data).
SSR20140208.mat
I would like to load all these 55 files into my script, run the program, and save accordingly with the name azimuth_SSR(Year)(Month)(Day) .
I have checked numerous websites and links, but most of them have pattern such as file(1) - file(20) .
Thanks.
Edit 1: So far, I am considering the following code.
file_name = inputdlg('Insert the file name.');
file_name = str2num(file_name{:});
load ('', 'file_name.mat')
Respuesta aceptada
Más respuestas (1)
Although beginners love making variable magically pop into existence in their workspaces, it is more robust to explicitly allocate to the output of load.
You can use dir to get a list of the files, and then load the data into a non-scalar structure. It would also be easy to obtain the path using uigetdir.
dir_path = 'sub_dir/project_dir/data_dir';
S = dir(fullfile(dir_path,'SSR*.mat'));
N = {S.name};
for k = numel(N):-1:1
out(k) = load(fullfile(dir_path,N{k}));
end
More detailed examples can be found here:
1 comentario
bio lim
el 7 de Jul. de 2015
Categorías
Más información sobre Workspace Variables and MAT Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!