Home > vbmeg > functions > common > utility > vb_table_insert.m

vb_table_insert

PURPOSE ^

Insert key_value table.

SYNOPSIS ^

function table = vb_table_insert(table, key_value)

DESCRIPTION ^

 Insert key_value table.
 [USAGE]
    table = vb_table_insert(table, key_value)
 [IN]
        table : table data. (if table is not created, please set empty(=[]))
    key_value : key-value data set(made by vb_key_value_pair.m)
 [OUT]
        table : updated table data.
 [see]
    vb_key_value_pair.m
    vb_table_query_value.m

 [example]
     tbl = [];
     % create record
     key = 'brain_file';
     value = 'Cortical model file (.brain.mat)';
     record = vb_key_value_pair(key, value);
     % insert
     tbl = vb_table_insert(tbl, record);
     % inquery
     value  = vb_table_query_value(tbl, key);

 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 table = vb_table_insert(table, key_value)
0002 % Insert key_value table.
0003 % [USAGE]
0004 %    table = vb_table_insert(table, key_value)
0005 % [IN]
0006 %        table : table data. (if table is not created, please set empty(=[]))
0007 %    key_value : key-value data set(made by vb_key_value_pair.m)
0008 % [OUT]
0009 %        table : updated table data.
0010 % [see]
0011 %    vb_key_value_pair.m
0012 %    vb_table_query_value.m
0013 %
0014 % [example]
0015 %     tbl = [];
0016 %     % create record
0017 %     key = 'brain_file';
0018 %     value = 'Cortical model file (.brain.mat)';
0019 %     record = vb_key_value_pair(key, value);
0020 %     % insert
0021 %     tbl = vb_table_insert(tbl, record);
0022 %     % inquery
0023 %     value  = vb_table_query_value(tbl, key);
0024 %
0025 % Copyright (C) 2011, ATR All Rights Reserved.
0026 % License : New BSD License(see VBMEG_LICENSE.txt)
0027 
0028 
0029 %
0030 % --- Previous check
0031 %
0032 if ~exist('table', 'var')
0033     error('table is a required parameter.');
0034 end
0035 if ~exist('key_value', 'var')
0036     error('key_value is a required parameter.');
0037 end
0038 if ~isstruct(key_value) || ...
0039    ~isfield(key_value, 'key') || ~isfield(key_value, 'value')
0040     error('Unknown key_value type was specified.');
0041 end
0042 
0043 %
0044 % --- Main Procedure
0045 %
0046 table = [table; key_value];
0047 
0048 %
0049 % --- After check
0050 %
0051 if nargout ~= 1
0052     error('You have to receive the updated table data.');
0053 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005