33% jload
44% or
55% jload(fname)
6+ % varlist=jload(fname)
7+ % [varlist, header]=jload(fname)
68% varlist=jload(fname,'param1',value1,'param2',value2,...)
79%
810% Load variables from a JSON or binary JSON file to a workspace
3335% can be used to adjust the parsing options
3436%
3537% output:
36- % varlist: a list of variables loaded
38+ % varlist: a struct with each subfield a variable stored in the file,
39+ % if output is ignored, the variables will be loaded to the
40+ % workspace specified by the 'ws' option, which by default
41+ % load the variables to the current workspace ('caller')
3742%
3843% examples:
3944% jload % load all variables in jamdata.jamm to the 'caller' workspace
4045% jload mydat.jamm
4146% jload('mydat.jamm','vars', {'v1','v2',...}) % load selected variables
42- % jload('mydat.jamm','simplifycell',1)
47+ % varlist= jload('mydat.jamm','simplifycell',1)
4348%
4449% license:
4550% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
4853%
4954
5055if (nargin == 0 )
51- filename= ' jamdata.jamm' ;
56+ filename= [ pwd filesep ' jamdata.jamm' ] ;
5257end
5358
5459opt= varargin2struct(varargin{: });
7580 header= loadfun(filename ,' ObjectID' ,1 , varargin{: });
7681end
7782
78- if (jsonopt(' Header' ,0 ,opt ))
79- varargout{1 }=header ;
80- return ;
81- end
82-
8383allvar= fieldnames(header .WorkspaceHeader );
8484
8585varlist= jsonopt(' vars' ,allvar ,opt );
9696 body= loadfun(filename ,' ObjectID' ,2 , varargin{: });
9797end
9898
99- for i= 1 : length(varlist )
100- assignin(ws , varlist{i }, body .WorkspaceData.(varlist{i }));
101- end
102-
103- if (nargout > 1)
104- varargout{1 }=varlist ;
99+ if (nargout == 0 )
100+ for i= 1 : length(varlist )
101+ assignin(ws , varlist{i }, body .WorkspaceData.(varlist{i }));
102+ end
103+ else
104+ varargout{1 }=rmfield(body .WorkspaceData ,setdiff(fieldnames(body .WorkspaceData ),varlist ));
105+ if (nargout > 1)
106+ varargout{2 }=header ;
107+ end
105108end
0 commit comments