write wrapper for matlabs save function -
i write wrapper save function of matlab predefined options (predefined version in case allow saving large files), i.e. this
save('parameters.mat', 'some', 'parameters', 'here', '-v.3'); should turn this
save_large('parameters.mat', 'some', 'parameters', 'here'); where save_large wrapper save version set '-v7.3':
function [ ] = save_large( filename, varargin ) %varargin allow multiple variable storing? %what write here save variables (declared chars) stored in %the workspace 'save_large' called version set '-v7.3'? end
because variables won't exist in scope of function save_large, have use evalin variable "caller" workspace.
using try can ensure variable exists in caller workspace.
to correct variable names within .mat file, either use (discouraged) eval function, or below method assigns of variables struct, , use -struct flag in save.
function save_large(filename, varargin) % set struct saving savestruct = struct(); n = 1:numel(varargin) % test if variable exists in caller workspace % trying assign struct % use parentheses creating field equal string varargin try savestruct.(varargin{n}) = evalin('caller', varargin{n}); % successful assignment struct, no action needed catch warning(['could not find variable: ', varargin{n}]); end end save(filename, '-struct', 'savestruct', '-v7.3'); end example
% create dummy variables , save them = magic(3); b = 'abc'; save_large test.mat b; % clear workspace rid of , b clear b exist var % false exist b var % false % load file load test.mat % , b in workspace exist var % true exist b var % true
Comments
Post a Comment