


ACTIVATEREPOSITORY - save the model fields separately
This function is required when a matlab session
is running low on memory, or when a model is very large.
By activating a repository (for example, 'repository.model'),
the model fields will each separately be saved and accessed when
needed. This will limit the memory use at the maximum;
Usage:
md=activaterepository(md)

0001 function md=activaterepository(md) 0002 %ACTIVATEREPOSITORY - save the model fields separately 0003 % 0004 % This function is required when a matlab session 0005 % is running low on memory, or when a model is very large. 0006 % By activating a repository (for example, 'repository.model'), 0007 % the model fields will each separately be saved and accessed when 0008 % needed. This will limit the memory use at the maximum; 0009 % 0010 % Usage: 0011 % md=activaterepository(md) 0012 0013 0014 %for each field of the model, we create an equivalent variable, with the same name, which we 0015 %save in the repository. 0016 0017 modelfields=fields(md); 0018 0019 %then save each of the big fields in their respective files 0020 for i=1:length(modelfields), 0021 field=char(modelfields(i)); 0022 eval([field '=md.' field ';']); 0023 0024 %anything NaN, will be saved 0025 0026 if isnumeric(eval(field)), 0027 if isnan(eval(field)), 0028 if exist(['.' md.repository '.' field],'file'); 0029 error(['Repository ' md.repository ' already exists! Delete all files starting with .' md.repository ' in your directory, before activating a new repository']); 0030 end 0031 eval(['save .' md.repository '.' field ' ' field]); 0032 end 0033 end 0034 end