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

vb_trial_extractor_tag_by_hand

PURPOSE ^

set tag to selected item

SYNOPSIS ^

function [data] = vb_trial_extractor_tag_by_hand(data, list_index, tag)

DESCRIPTION ^

 set tag to selected item
 [USAGE]
    [data] = vb_trial_extractor_tag_by_hand(data, list_index, tag);
 [IN]
          data : vb_trial_extractor object.
    list_index : selected index on trial listbox. [Nx1]
                 (not data index)
           tag : tag name
 [OUT]
          data : 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_tag_by_hand(data, list_index, tag)
0002 % set tag to selected item
0003 % [USAGE]
0004 %    [data] = vb_trial_extractor_tag_by_hand(data, list_index, tag);
0005 % [IN]
0006 %          data : vb_trial_extractor object.
0007 %    list_index : selected index on trial listbox. [Nx1]
0008 %                 (not data index)
0009 %           tag : tag name
0010 % [OUT]
0011 %          data : vb_trial_extractor object.
0012 %
0013 % Copyright (C) 2011, ATR All Rights Reserved.
0014 % License : New BSD License(see VBMEG_LICENSE.txt)
0015 
0016 %
0017 % --- Previous check
0018 %
0019 if ~exist('data', 'var')
0020     error('data is a required parameter.');
0021 end
0022 if ~exist('list_index', 'var')
0023     error('list_index is a required parameter.');
0024 end
0025 if size(list_index, 2) ~= 1
0026     error('index shape should be [Nx1].');
0027 end
0028 if ~exist('tag', 'var')
0029     error('tag is a required parameter.');
0030 end
0031 if ~ischar(tag)
0032     error('tag should be string');
0033 end
0034 
0035 %
0036 % --- Main Procedure
0037 %
0038 
0039 % Duplicate check between new tag and exist tags
0040 exist_tags = cell(0);
0041 for k=1:length(data.label_list)
0042     exist_tags{k} = vb_tag_get_tag_name(data.label_list{k});
0043 end
0044 
0045 dup_tags = cell(0);
0046 dup_ix   = strmatch(tag, exist_tags, 'exact');
0047 
0048 if ~isempty(dup_ix)
0049     dup_tags = exist_tags(dup_ix);
0050 end
0051 
0052 if length(dup_tags)
0053    msg = sprintf('Following labels already exists, Continue?\n');
0054    for k=1:length(dup_tags)
0055        msg = [msg, sprintf('%s\n', dup_tags{k})];
0056    end
0057    res = questdlg(msg, 'Confirm', 'Yes', 'No', 'Yes');
0058    if strcmpi(res, 'no')
0059        return;
0060    else
0061        data.label_list(dup_ix) = []; % remove duplicate tag.
0062    end
0063 end
0064 
0065 % Create new tag and register trial index
0066 tag_obj = vb_tag_new(tag);
0067 
0068 % extract data index
0069 data_index = data.showing_trial_ix(list_index);
0070 
0071 % register trial
0072 tag_obj = vb_tag_add_trial_index(tag_obj, data_index);
0073 data.label_list{length(data.label_list)+1} = tag_obj;
0074 
0075 %
0076 % --- After check
0077 %
0078 if nargout ~= 1
0079     error('function caller should receive vb_trial_extractor obj.');
0080 end

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