0001 function [obj, ch_data, from, to] = vb_continuous_file_get_sample(obj, ch_list, from, to)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
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
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
0075 MARGIN = ceil(freq * 10);
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
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
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
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 if nargout < 1
0131 error('function caller should receive return values');
0132 end
0133
0134