Home > functions > gui > preAnalysis > trial_extractor > vb_trial_extractor_add_trial.m

vb_trial_extractor_add_trial

PURPOSE ^

Add new trial.

SYNOPSIS ^

function [data] = vb_trial_extractor_add_trial(data)

DESCRIPTION ^

 Add new trial.
 [USAGE]
    [data] = vb_trial_extractor_add_trial(data);
 [IN]
    data : vb_trial_extractor object.
 [OUT]
    data : updated vb_trial_extractor object.

 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 [data] = vb_trial_extractor_add_trial(data)
0002 % Add new trial.
0003 % [USAGE]
0004 %    [data] = vb_trial_extractor_add_trial(data);
0005 % [IN]
0006 %    data : vb_trial_extractor object.
0007 % [OUT]
0008 %    data : updated vb_trial_extractor object.
0009 %
0010 % Copyright (C) 2011, ATR All Rights Reserved.
0011 % License : New BSD License(see VBMEG_LICENSE.txt)
0012 
0013 %
0014 % --- Previous check
0015 %
0016 if ~exist('data', 'var')
0017     error('data is a required parameter.');
0018 end
0019 
0020 %
0021 % --- Main Procedure
0022 %
0023 H = data.H;
0024 
0025 % Sample Frequency [Hz]
0026 freq = vb_continuous_file_get_sample_freq(data.continuous_file);
0027 [Nsample] = vb_continuous_file_get_Nsample(data.continuous_file);
0028 
0029 % Sample number for Pre/Post period
0030 pretrigger  = ceil(data.trial_setting.pretrigger_ms  *(freq/1000));
0031 posttrigger = ceil(data.trial_setting.posttrigger_ms *(freq/1000));
0032 
0033 err = true;
0034 while(err)
0035     onset_time_sec = inputdlg('Input trial onset time [sec]', 'Add trial');
0036     if isempty(onset_time_sec), return; end
0037     if isnan(str2double(onset_time_sec))
0038         h = errordlg('Input value is not a number.', 'Add trial');
0039         waitfor(h);
0040         continue; % back to top of while
0041     end
0042 
0043     % calc sampling number
0044     onset_time       = round(str2double(onset_time_sec{1}) * freq)+1; % 0[sec] = sample:1
0045     pretrigger_time  = onset_time - pretrigger;
0046     posttrigger_time = onset_time + posttrigger - 1;
0047 
0048     if pretrigger_time <= 0
0049         h = errordlg('Cant''t specify the onset time because pretrigger position is less than 0.', 'Add trial');
0050         waitfor(h);
0051         continue; % back to top of while
0052     elseif posttrigger_time > Nsample
0053         h = errordlg('Can''t specify the onset time because posttrigger position is larger than data length.', 'Add trial');
0054         waitfor(h);
0055         continue; % back to top of while
0056     end
0057     err = false; % normal exit
0058 end
0059 
0060 % Create trial and add list
0061 trial_obj = vb_trial_new(pretrigger_time, posttrigger_time, onset_time);
0062 data.trial_list = [data.trial_list; trial_obj];
0063 new_ix = length(data.trial_list);
0064 
0065 %
0066 % --- Add created trial to selected label
0067 %
0068 
0069 % multiple selection is prohibited by listbox
0070 labels   = get(H.tag_listbox, 'String');
0071 selected = get(H.tag_listbox, 'Value');
0072 selected_label = labels{selected};
0073 
0074 % add trial to selected label
0075 [tag_obj, nth] = vb_tag_util_find_tag(data.label_list, selected_label);
0076 if ~isempty(tag_obj)
0077     data.label_list{nth} = vb_tag_add_trial_index(data.label_list{nth}, new_ix);
0078     % Update viewer if a viewer is opened.
0079     data = vb_trial_extractor_notify_viewer(data, selected_label);
0080 end
0081 
0082 %
0083 % --- After check
0084 %
0085 if nargout ~= 1
0086     error('function caller should receive this object.');
0087 end

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