Load Multiple .mat Files to Matlab workspace

前端 未结 3 552
抹茶落季
抹茶落季 2020-12-20 02:52

I\'m trying to load several .mat files to the workspace. However, they seem to overwrite each other. Instead, I want them to append. I am aware that I can do something li

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 03:20

    Clark's answer and function actually solved my situation perfectly... I just added the following bit of code to make it a little less tedious. Just add this to the beginning and get rid of the "files" argument:

    [files,pathname] = uigetfile('*.mat', 'Select MAT files (use CTRL/COMM or SHIFT)', ...
       'MultiSelect', 'on'); 
    

    Alternatively, it could be even more efficient to just start with this bit:

    [pathname] = uigetdir('C:\');
    files = dir( fullfile(pathname,'*.mat') );   %# list all *.mat files
    files = {files.name}';                       %# file names
    
    data = cell(numel(files),1);                 %# store file contents
    for i=1:numel(files)
        fname = fullfile(pathname,files{i});     %# full path to file
        data{i} = load(fname);                   %# load file
    end
    

    (modified from process a list of files with a specific extension name in matlab).

    Thanks, Jason

提交回复
热议问题