loadgenericdata

loadgenericdata(varfile, vartype, fields, varname, args)

loadgenericdata() - Loads data of a specified type from file or data structure.

VAR = LOADGENERICDATA(VARFILE, VARTYPE)
VAR = LOADGENERICDATA(VARFILE, VARTYPE, FIELDS)
VAR = LOADGENERICDATA(VARFILE, VARTYPE, FIELDS, VARNAME)
VAR = LOADGENERICDATA(VARFILE, VARTYPE, FIELDS, VARNAME, ARGS)

Loads data from a variable or M-file or MAT-file and checks that it
matches a specified type.

Inputs:
    VARFILE : Variable containing the data structure or a string
              containing the name of a function M-file or a MAT-file
              on the MATLAB/Octave path. If no file extension is provided
              it will attempt to load a MAT-file with that name and,
              if not found, will call a function by that name to
              get the data. The function M-file should return a
              single argument containing the data. A MAT-file should
              either contain a single variable with the desired data
              or provide the variable name in VARNAME.
    VARTYPE : String or cell array of strings with, in order of
              priority, the data structure type to be returned.
              Valid values are 'struct', 'cell' and 'array'.
    FIELDS :  (optional) String or cell array of strings containing
              a list of required fields in case the VARTYPE is struct.
              If a required field is missing it will throw an error.
    VARNAME   (optional) String containing the name of the variable to
              extract when loading a MAT-file. If not provided, the
              default is to extract the 1st variable, regardless of name.
    ARGS :    (optional) Scalar or cell array of values that are passed
              as input function arguments to VARFILE if it is an M-file.

Output:
    VAR : Returned data structure of the first matching VARTYPE.