[137] | 1 | %PR_LOADMATFILE Load matfile for this mfile, if it exist
|
---|
| 2 | %
|
---|
| 3 | % A = PR_LOADMATFILE(MATFILE)
|
---|
| 4 | %
|
---|
| 5 | % Loads the dataset stored in the matfile. Default matfile is the name of
|
---|
| 6 | % the calling routine. The output A is empty if MATFILE does not exist.
|
---|
| 7 | %
|
---|
| 8 | % [A1,A2,..] = PR_LOADMATFILE(MATFILE,NARGOUTCOUNT)
|
---|
| 9 | %
|
---|
| 10 | % In case multiple matfiles are stored for the calling routine, it is
|
---|
| 11 | % assumed they all contain a dataset: train set, test set, validation set,
|
---|
| 12 | % etcetera. In case NARGOUTCOUNT (NARGOUT of the calling routine) equals 1,
|
---|
| 13 | % the combined dataset is loaded and returned in A (A1).
|
---|
| 14 | % In case NARGOUTCOUNT > 1, the subsets are are loaded into A1, A2, ...
|
---|
| 15 | %
|
---|
| 16 | % SEE ALSO
|
---|
| 17 | % DATASETS, PRDATASETS, PR_SAVEMATFILE, PR_DOWNLOAD_UCI
|
---|
| 18 |
|
---|
| 19 | function varargout = pr_loadmatfile(name)
|
---|
| 20 |
|
---|
| 21 | varargout = cell(1,nargout);
|
---|
| 22 |
|
---|
| 23 | if nargin < 1 || isempty(name)
|
---|
| 24 | name = pr_callername;
|
---|
| 25 | end
|
---|
[151] | 26 | matfile = fullfile(fullfile(fileparts(which(mfilename)),'data'),name);
|
---|
| 27 | if exist([matfile '.mat'],'file') ~= 2,
|
---|
| 28 | return
|
---|
| 29 | end
|
---|
[137] | 30 |
|
---|
| 31 | if nargout == 1
|
---|
[151] | 32 | % varargout{1} = loadmatf([matfile '.mat']);
|
---|
| 33 | varargout{1} = file2dset([matfile '.mat']);
|
---|
[137] | 34 | else
|
---|
| 35 | for i=1:nargout
|
---|
[151] | 36 | % varargout{i} = loadmatf([matfile '_' num2str(i) '.mat']);
|
---|
| 37 | varargout{i} = file2dset([matfile '_' num2str(i) '.mat']);
|
---|
[137] | 38 | end
|
---|
| 39 | end
|
---|
| 40 |
|
---|
| 41 | return
|
---|
| 42 |
|
---|
| 43 | function a = loadmatf(matfile)
|
---|
| 44 | if exist(matfile,'file') == 2
|
---|
| 45 | warning('OFF','MATLAB:indeterminateFields');
|
---|
| 46 | s = prload(matfile);
|
---|
| 47 | warning('ON','MATLAB:indeterminateFields');
|
---|
| 48 | fields = fieldnames(s);
|
---|
| 49 | a = s.(fields{1});
|
---|
| 50 | a = pr_dataset(a); % take care of prtools4 and prtools5 datasets
|
---|
| 51 | else
|
---|
| 52 | a = [];
|
---|
| 53 | end
|
---|
| 54 | return
|
---|