Home > data-access > get_variable_from_specified_directory.m

get_variable_from_specified_directory

PURPOSE ^

Get the data associated with the variable for the subject from specified

SYNOPSIS ^

function [ var_data ] = get_variable_from_specified_directory( subj_id, sub_directory, varname )

DESCRIPTION ^

Get the data associated with the variable for the subject from specified
sub directory in this subject's folder
   get_variable_from_specified_directory(SUBJECT_ID, SUB_DIRECTORY,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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ var_data ] = get_variable_from_specified_directory( subj_id, sub_directory, varname )
0002 %Get the data associated with the variable for the subject from specified
0003 %sub directory in this subject's folder
0004 %   get_variable_from_specified_directory(SUBJECT_ID, SUB_DIRECTORY,VARIBLE_NAME)
0005 %       Finds the path of the variable using get_variable_path, then loads
0006 %       the contents of the variable file, returning just the data portion.
0007 %
0008 %   By convention, the data array is one of the data types used by the
0009 %   visualization program: event, cevent, cstream, or cont.
0010 %
0011 
0012     if nargin < 3 || isempty(subj_id) || isempty(sub_directory) || isempty(varname)
0013        error('You must specify subject ID, subdirectory and variable name'); 
0014     end
0015 
0016     var_dir = [get_subject_dir(subj_id) filesep() sub_directory];
0017     if exist(var_dir, 'dir')==0
0018         error(['The directory ' var_dir ' is not existed']);
0019     end
0020     filename = [var_dir filesep() varname '.mat'];
0021 
0022     if ~ exist(filename, 'file')
0023         error('Requested variable doesn''t exist! %d / %s \n(No such file: ''%s'')', ...
0024             subj_id, varname, filename);
0025     end
0026 
0027     try
0028         contents = load(filename);
0029         var_data = contents.sdata.data;
0030     catch OrigEx
0031         informative = MException('get_variable:bad_format', ...
0032             'Problem accessing %d / %s (%s)', ...
0033             subj_id, varname, filename);
0034         informative = informative.addCause(OrigEx);
0035         throw(informative);
0036     end
0037 end

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005