11function saveParamProfile(expType , profileName , params )
22% DAT.SAVEPARAMPROFILE Stores the named parameters for experiment type
3- % TODO
4- % - Figure out how to save struct without for-loop in 2016b!
3+ % Saves a parameter structure in a MAT file called 'parameterProfiles'.
4+ % Each field of this struct is an expType, and each nested field
5+ % is the set name. Parameters of a given expType can be loaded using the
6+ % DAT.LOADPARAMPROFILES function.
7+ %
8+ % Inputs:
9+ % expType (char): The name of the experiment type, e.g. ChoiceWorld.
10+ % profileName (char): The name of the parameter set being saved. If
11+ % the name already exists in the file for a given expType, it is
12+ % overwritten.
13+ % params (struct): A parameter structure to be saved.
14+ %
15+ % Example:
16+ % dat.saveParamProfile('ChoiceWorld', 'defSet', exp.choiceWorldParams)
17+ % profiles = dat.loadParamProfiles('ChoiceWorld');
18+ % p = exp.Parameters(profiles.defSet);
19+ %
20+ % See also DAT.LOADPARAMPROFILES, DAT.PATHS
21+ %
522% Part of Rigbox
623
724% 2013-07 CB created
825% 2017-02 MW adapted to work in 2016b
926
10- % path to repositories
27+ % If main repo folders don't exist yet, create them
28+ repos = dat .reposPath(' main' );
29+ cellfun(@mkdir , repos(~file .exists(repos )))
30+
31+ % Path to repository files
1132fn = ' parameterProfiles.mat' ;
12- repos = fullfile(dat .reposPath( ' main ' ) , fn );
33+ repos = fullfile(repos , fn );
1334
14- % load existing profiles for specified expType
35+ % Load existing profiles for specified expType
1536profiles = dat .loadParamProfiles(expType );
16- % add (or replace) the params with a field named by profile
37+ % Add (or replace) the params with a field named by profile
1738profiles.(profileName ) = params ;
18- % wrap in a struct for saving
39+ % Wrap in a struct for saving
1940set = struct ;
2041set.(expType ) = profiles ;
2142
22- % save the updated set of profiles to each repos
23- % where files exist already, append
24- % cellfun(@(p) save(p, '-struct', 'set', '-append'),
25- % file.filterExists(repos, true)); % Had to change her to a for loop, sorry
26- % Chris!
27- p = file .filterExists(repos , true );
28- for i = 1 : length(p )
29- save(p{i }, ' -struct' , ' set' , ' -append' )
30- end
31- % and any that don't we should create from scratch
32- p = file .filterExists(repos , false );
33- for i = 1 : length(p )
34- save(p{i }, ' -struct' , ' set' )
35- end
36- % cellfun(@(p) save(p, '-struct', 'set'), file.filterExists(repos, false));
43+ % Save the updated set of profiles to each repos where files exist already,
44+ % append
45+ saveFn = @(p ,name ,varargin ) save(p , ' -struct' , ' name' , varargin{: });
46+ cellfun(@(p ) saveFn(p , set , ' -append' ) , file .filterExists(repos , true ));
3747
38- end
48+ % Any that don't we should create from scratch
49+ cellfun(@(p ) saveFn(p , set ), file .filterExists(repos , false ));
0 commit comments