简体   繁体   中英

MATLAB: Opening and Editing Files nested in folders in folders

I'm working on a project where I need to pull files from this expansive directory with many subfolders nested in folders.

I'm a complete novice when it comes to using matlab and directories, and I was wondering if anyone could help get me started!

I've been using mainFolder = dir(fullfile(uigetfile)) to open the original main directory and then grabbing other folders using more fullfile and wildcards for things they contain. I just don't know how many sub_folders MATLAB will open and let me edit

I've written in english essentially what I need the code to accomplish - I'm not expecting someone to write this for me, just provide me with tips on how to get started!

%function getvariables

%open mainFolder

%open "dates" %name of subfolder in mainFolder

%open "experiment" %name of subfolder in dates

%open "analysis" %name of subfolder in experiment

 if .mat filename includes the string pre
     % pull variables from the .mat file
     % figure out if it contains a certain string of numbers ex. 1234
 if .mat filename includes the string post
     % pull other variables from the .mat file
     % figure out if it contains a certain string of numbers ex. 1234
 else
     % pull other stuff
     % figure out if it contains a certain string of numbers ex. 1234
 end

%load .mat file with the same numbers ex. 1234.mat from ANOTHER folder

%add the variables I grabbed from the pre/post/else .mat files to the loaded 1234.mat file

%save the newly updated 1234.mat file

%run this for a hundred or so different files...

Thanks,

ML

Check out subdir! On the file exchange, its an awesome function that can return all folders and all files in expansive subfolders, and you can filter file names by extension and whatnot.

http://www.mathworks.com/matlabcentral/fileexchange/15859-subdir-a-recursive-file-search

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM