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

vb_trial_extractor_edit_trial

PURPOSE ^

Edit trial.

SYNOPSIS ^

function [data] = vb_trial_extractor_edit_trial(data)

DESCRIPTION ^

 Edit trial.
 [USAGE]
    [data] = vb_trial_Extractor_edit_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_edit_trial(data)
0002 % Edit trial.
0003 % [USAGE]
0004 %    [data] = vb_trial_Extractor_edit_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 % Selected trial
0026 N = get(H.trial_set_listbox, 'Value');
0027 edit_index = data.showing_trial_ix(N);
0028 
0029 trial = data.trial_list(edit_index);
0030 
0031 % Sample Frequency [Hz]
0032 freq = vb_continuous_file_get_sample_freq(data.continuous_file);
0033 [Nsample] = vb_continuous_file_get_Nsample(data.continuous_file);
0034 
0035 % Input onset time
0036 onset = trial.onset;
0037 MEGinfo = vb_continuous_file_get_meg_info(data.continuous_file);
0038 MEGinfo = vb_meginfo_set_pre_trigger(MEGinfo, 0);
0039 onset_sec = vb_index_to_time(onset, MEGinfo) / 1000;%[msec]->[sec]
0040 
0041 err = true;
0042 while(err)
0043     onset_sec_edit = inputdlg('Input trial onset time [sec]', ...
0044                               'Edit trial', ...
0045                               1, {num2str(onset_sec, 6)});
0046     if isempty(onset_sec_edit), return; end
0047     if isnan(str2double(onset_sec_edit))
0048         h = errordlg('Input value is not a number.', 'Edit trial');
0049         waitfor(h);
0050         continue; % back to top of while
0051     end
0052 
0053     % Sample number for Pre/Post period
0054     pretrigger  = ceil(data.trial_setting.pretrigger_ms  *(freq/1000));
0055     posttrigger = ceil(data.trial_setting.posttrigger_ms *(freq/1000));
0056 
0057     % calc sampling number
0058     onset_time       = round(str2double(onset_sec_edit{1}) * freq)+1; % 0[sec] = sample:1
0059     pretrigger_time  = onset_time - pretrigger;
0060     posttrigger_time = onset_time + posttrigger - 1;
0061 
0062     if pretrigger_time <= 0
0063         h = errordlg('Cant''t specify the onset time because pretrigger position is less than 0.', 'Edit trial');
0064         waitfor(h);
0065         continue; % back to top of while
0066     elseif posttrigger_time > Nsample
0067         h = errordlg('Can''t specify the onset time because posttrigger position is larger than data length.', 'Edit trial');
0068         waitfor(h);
0069         continue; % back to top of while
0070     end
0071     err = false; % normal exit of while
0072 end
0073 
0074 % Replace trial
0075 trial_obj = vb_trial_new(pretrigger_time, posttrigger_time, onset_time);
0076 data.trial_list(edit_index) = trial_obj; % overwrite
0077 
0078 %
0079 % --- Update viewer if a viewer is opened.
0080 %
0081 
0082 % multiple selection is prohibited by listbox
0083 labels   = get(H.tag_listbox, 'String');
0084 selected = get(H.tag_listbox, 'Value');
0085 selected_label = labels{selected};
0086 data = vb_trial_extractor_notify_viewer(data, selected_label);
0087 
0088 %
0089 % --- After check
0090 %
0091 if nargout ~= 1
0092     error('function caller should receive this object.');
0093 end

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