0001 function index = vb_time_to_index(time,meg_info)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 sample_freq = vb_meginfo_get_sampling_frequency(meg_info);
0014 Nsample = vb_meginfo_get_sample_number(meg_info);
0015 pretrigger = vb_meginfo_get_pre_trigger(meg_info);
0016
0017
0018 sampling_length = 1000/sample_freq;
0019
0020
0021 sampling_point = -(sampling_length * pretrigger) : sampling_length : ...
0022 (sampling_length * (Nsample-pretrigger-1));
0023
0024 for k=1:length(time)
0025 if time(k) < min(sampling_point)
0026 time(k) = min(sampling_point);
0027 elseif time(k) > max(sampling_point)
0028 time(k) = max(sampling_point);
0029 end
0030
0031
0032 index(k) = min(find(sampling_point>=time(k)));
0033 end