Home > functions > gui > preAnalysis > trial_extractor > private > vb_continuous_file_get_sample.m

vb_continuous_file_get_sample

PURPOSE ^

return specified channel data.

SYNOPSIS ^

function [obj, ch_data, from, to] = vb_continuous_file_get_sample(obj, ch_list, from, to)

DESCRIPTION ^

 return specified channel data.
 [USAGE]
    [obj, ch_data] = vb_continuous_file_get_sample(obj, ch_list, from, to);
 [IN]
        obj : continuous file object.
    ch_list : channel name list to get data {Nx1}
       from : get from this sample number.
         to : get data 'from' to 'to' .
 [OUT]
        obj : continuous file object.
    ch_data : specified channel data
       from : got from this sample number.
         to : got data until this sample number.

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [obj, ch_data, from, to] = vb_continuous_file_get_sample(obj, ch_list, from, to)
0002 % return specified channel data.
0003 % [USAGE]
0004 %    [obj, ch_data] = vb_continuous_file_get_sample(obj, ch_list, from, to);
0005 % [IN]
0006 %        obj : continuous file object.
0007 %    ch_list : channel name list to get data {Nx1}
0008 %       from : get from this sample number.
0009 %         to : get data 'from' to 'to' .
0010 % [OUT]
0011 %        obj : continuous file object.
0012 %    ch_data : specified channel data
0013 %       from : got from this sample number.
0014 %         to : got data until this sample number.
0015 %
0016 % Copyright (C) 2011, ATR All Rights Reserved.
0017 % License : New BSD License(see VBMEG_LICENSE.txt)
0018 
0019 %
0020 % --- Previous check
0021 %
0022 if ~exist('obj', 'var')
0023     error('obj is a required parameter.');
0024 end
0025 if ischar(ch_list)
0026     ch_list = {ch_list};
0027 end
0028 if ~iscellstr(ch_list)
0029     error('ch_list should be cell string.');
0030 end
0031 if ~exist('from', 'var')
0032     error('from is a required parameter.');
0033 end
0034 if ~exist('to', 'var')
0035     error('to is a required parameter.');
0036 end
0037 
0038 if ~isfield(obj, 'cache_data')
0039     obj.cache_data = struct;
0040 end
0041 if ~isfield(obj.cache_data, 'sample_list')
0042     obj.cache_data.sample_list = [];
0043 end
0044 if ~isfield(obj.cache_data, 'data')
0045     obj.cache_data.data = [];
0046 end
0047 if ~isfield(obj.cache_data, 'Name')
0048     obj.cache_data.Name = [];
0049 end
0050 
0051 %
0052 % --- Main Procedure
0053 %
0054 Nsample = vb_continuous_file_get_Nsample(obj);
0055 if from <= 0
0056     from = 1;
0057 end
0058 if to > Nsample
0059     to = Nsample;
0060 end
0061 
0062 freq = vb_continuous_file_get_sample_freq(obj);
0063 
0064 
0065 cix_from = [];
0066 cix_to   = [];
0067 
0068 if ~isempty(obj.cache_data.sample_list)
0069     cix_from = find(obj.cache_data.sample_list == from);
0070     cix_to   = find(obj.cache_data.sample_list == to);
0071 end
0072 
0073 if isempty(cix_from) || isempty(cix_to)
0074     % miss hit
0075     MARGIN = ceil(freq * 10); % margin pre-post data
0076     if from-MARGIN < 0
0077         read_from = 1;
0078     else
0079         read_from = from-MARGIN;
0080     end
0081     if to + MARGIN > Nsample
0082         read_to = Nsample;
0083     else
0084         read_to = to + MARGIN;
0085     end
0086     read_len = read_to - read_from + 1;
0087 
0088     % load data
0089     if ~isempty(obj.read_ch_list)
0090         load_spec.ChannelName = obj.read_ch_list;
0091     else
0092         load_spec.ChannelType = 'ALL';
0093     end
0094     load_spec.Pretrigger  = 0;
0095     load_spec.Trigger     = read_from;
0096     load_spec.Posttrigger = read_to - read_from;
0097     h = msgbox('Now reading data...', 'Please wait');
0098     bh = findall(h, 'Style', 'pushbutton');
0099     set(bh, 'Visible', 'off', 'Enable', 'off');
0100     drawnow; pause(0.1);
0101     [obj.cache_data.data, ch_info] = vb_load_meg_data(obj.filename, load_spec);
0102     obj.cache_data.Name = ch_info.Name;
0103     if ishandle(h), delete(h); end
0104     obj.cache_data.sample_list = [read_from:read_to];
0105 end
0106 
0107 data_ix = [];
0108 for k=1:length(ch_list)
0109     data_ix = [data_ix; strmatch(ch_list{k}, obj.cache_data.Name, 'exact')];
0110 end
0111 % return data
0112 cix_from = find(obj.cache_data.sample_list == from);
0113 cix_to   = find(obj.cache_data.sample_list == to);
0114 ch_data = obj.cache_data.data(data_ix, cix_from:cix_to);
0115 
0116 from = obj.cache_data.sample_list(cix_from);
0117 to   = obj.cache_data.sample_list(cix_to);
0118 
0119 % % debug
0120 % if size(obj.cache_data.sample_list, 2) ~= 1787500
0121 %     dbstack;
0122 %     a = 1;
0123 % end
0124 
0125 
0126 
0127 %
0128 % --- After check
0129 %
0130 if nargout < 1
0131     error('function caller should receive return values');
0132 end
0133 
0134

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005