Home > data-access > get_variable.m

get_variable

PURPOSE ^

Get the data associated with the variable for the subject

SYNOPSIS ^

function [ var_data ] = get_variable( subj_id, varname, force )

DESCRIPTION ^

Get the data associated with the variable for the subject
   get_variable(SUBJECT_ID, VARIBLE_NAME)
       Finds the path of the variable using get_variable_path, then loads
       the contents of the variable file, returning just the data portion.

   By convention, the data array is one of the data types used by the
   visualization program: event, cevent, cstream, or cont.

   For a list of the variables available for a particular subject, try
   list_variables(SUBJECT_ID).  To search for a subject with a particular
   variable, try find_subjects({VARIABLE, VARIABLE}).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ var_data ] = get_variable( subj_id, varname, force )
0002 %Get the data associated with the variable for the subject
0003 %   get_variable(SUBJECT_ID, VARIBLE_NAME)
0004 %       Finds the path of the variable using get_variable_path, then loads
0005 %       the contents of the variable file, returning just the data portion.
0006 %
0007 %   By convention, the data array is one of the data types used by the
0008 %   visualization program: event, cevent, cstream, or cont.
0009 %
0010 %   For a list of the variables available for a particular subject, try
0011 %   list_variables(SUBJECT_ID).  To search for a subject with a particular
0012 %   variable, try find_subjects({VARIABLE, VARIABLE}).
0013 if ~exist('force', 'var') || isempty(force)
0014     force = 0;
0015 end
0016 
0017 if ischar(subj_id)
0018     filename = [subj_id varname '.mat'];
0019 else
0020     filename = get_variable_path(subj_id, varname);
0021 end
0022 var_data = [];
0023 if ~exist(filename, 'file')
0024     if ~force
0025         error('Requested variable doesn''t exist! %d / %s \n(No such file: ''%s'')', ...
0026             subj_id, varname, filename);
0027     end
0028 else
0029     
0030     try
0031         contents = load(filename);
0032         if isfield(contents, 'sdata') && isfield(contents.sdata, 'data')
0033             var_data = contents.sdata.data;
0034         else
0035             var_data = contents;
0036         end
0037     catch OrigEx
0038         informative = MException('get_variable:bad_format', ...
0039             'Problem accessing %d / %s (%s)', ...
0040             subj_id, varname, filename);
0041         informative = informative.addCause(OrigEx);
0042         throw(informative);
0043     end
0044 end

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005