Home > classes > @ao > fromMAT.m

fromMAT

PURPOSE ^

FROMMAT Construct an ao from a .MAT file

SYNOPSIS ^

function a = fromMAT(a, pli)

DESCRIPTION ^

 FROMMAT Construct an ao from a .MAT file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 FUNCTION:    fromMAT

 DESCRIPTION: Construct an ao from a .MAT file

 CALL:        a = fromMAT(a, pl)

 PARAMETER:
              pl:       Parameter list object

 HISTORY:     07-05-2007 Hewitson
              Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % FROMMAT Construct an ao from a .MAT file
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % FUNCTION:    fromMAT
0005 %
0006 % DESCRIPTION: Construct an ao from a .MAT file
0007 %
0008 % CALL:        a = fromMAT(a, pl)
0009 %
0010 % PARAMETER:
0011 %              pl:       Parameter list object
0012 %
0013 % HISTORY:     07-05-2007 Hewitson
0014 %              Creation
0015 %
0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0017 
0018 function a = fromMAT(a, pli)
0019 
0020 VERSION = '$Id: fromMAT.m,v 1.6 2008/08/01 13:19:42 ingo Exp $';
0021 
0022 % get AO info
0023 ii = ao.getInfo('ao', 'From MAT File');
0024 
0025 % Set the method version string in the minfo object
0026 ii.setMversion([VERSION '-->' ii.mversion]);
0027 
0028 % Get the filename
0029 if ischar(pli)
0030   pli = plist('filename', pli);
0031 end
0032 
0033 pl = combine(pli, ao.getDefaultPlist('From MAT File'));
0034 filename = find(pl, 'filename');
0035 
0036 % Load the mat file
0037 in = load(filename);
0038 % Is this an AO?
0039 if isfield(in, 'a')
0040   a = in.a;
0041 % Or a data file
0042 else
0043   % Then we try for a numerical data set in
0044   % the first numerical field we come to
0045   fnames = fieldnames(in);
0046   for jj=1:length(fnames)
0047     if isnumeric(in.(fnames{jj}))
0048       % get the data from here
0049       data = in.(fnames{jj});
0050       ss = size(data);
0051       if ss(1) > 2
0052         warning('!!! I can only handle data files with two columns: time and amplitude. Additional columns are ignored.');
0053       end
0054       if ss(1) > ss(2)
0055         data = data.';
0056       end
0057       if ss(1) < 2
0058         x  = data(1,:);
0059         fs = 1;
0060         a.data = tsdata(x, fs);
0061       else
0062         % t from column 1
0063         t = data(1,:);
0064         % x from column 2
0065         x = data(2,:);
0066         a.data = tsdata(t,x);
0067       end
0068       % ignore the other fields
0069       warning('!!! Found a numeric field called %s. Ignoring all others.', fnames{jj});
0070       
0071       % Add history for this constructor
0072       a.addHistory(ii, pli, [], []);
0073       break;
0074     end
0075   end
0076 
0077   % Set the AO name
0078   a.setName(filename, 'internal');
0079 end
0080

Generated on Thu 14-Aug-2008 14:29:45 by m2html © 2003