Home > functions > common > utility > vb_edit_struct.m

vb_edit_struct

PURPOSE ^

edit struct field by input dlg.

SYNOPSIS ^

function [parm, cancelled] = vb_edit_struct(parm, caption)

DESCRIPTION ^

 edit struct field by input dlg.
 [USAGE]
    [parm, cancelled] = vb_edit_struct(<parm> [,caption]);
 [IN]
       parm : <<structure>> to be editted parameter.
    caption : <<char array>> window caption
 [OUT]
         parm : <<structure>> editted parameter.
    cancelled : true : If edit operation is cancelled, this flag switched true.
                false
 [NOTE]
    編集できるfieldのタイプは, scalar, matrix, char arrayの2種類


 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 [parm, cancelled] = vb_edit_struct(parm, caption)
0002 % edit struct field by input dlg.
0003 % [USAGE]
0004 %    [parm, cancelled] = vb_edit_struct(<parm> [,caption]);
0005 % [IN]
0006 %       parm : <<structure>> to be editted parameter.
0007 %    caption : <<char array>> window caption
0008 % [OUT]
0009 %         parm : <<structure>> editted parameter.
0010 %    cancelled : true : If edit operation is cancelled, this flag switched true.
0011 %                false
0012 % [NOTE]
0013 %    編集できるfieldのタイプは, scalar, matrix, char arrayの2種類
0014 %
0015 %
0016 % Copyright (C) 2011, ATR All Rights Reserved.
0017 % License : New BSD License(see VBMEG_LICENSE.txt)
0018 
0019 %
0020 % --- Previous check
0021 %
0022 if ~exist('parm', 'var')
0023     error('parm is a required parameter.');
0024 end
0025 if ~exist('caption', 'var')
0026     caption = 'Parameter';
0027 end
0028 
0029 %
0030 % --- Main Procedure
0031 %
0032 cancelled = false;
0033 parm_names = fieldnames(parm);
0034 Nfield = length(parm_names);
0035 % inputdlgの仕様でparm_names, parm_valueはセル配列(中身は文字列)である必要がある
0036 parm_value = cell(Nfield, 1);
0037 numeric_flag = zeros(Nfield, 1); % 数値は一旦文字列に変換。あとで数値に戻す
0038 col_size = zeros(Nfield, 1);     % matrixの場合、inputdlgの行数を増やす
0039 
0040 for k=1:Nfield
0041     tmp = parm.(parm_names{k});
0042     [col_size(k), n] = size(tmp);
0043     if col_size(k) <= 0, col_size(k) = 1; end
0044     if isnumeric(tmp)
0045         tmp = num2str(tmp);
0046         numeric_flag(k) = true;
0047     end
0048     parm_value{k} = tmp;
0049 end
0050 
0051 % display dialog
0052 input = inputdlg(parm_names, caption, col_size, parm_value, 'on');
0053 
0054 % check cancell or not
0055 if isempty(input)
0056     cancelled = true;
0057 else
0058     % parm構造体再構築
0059     for k=1:Nfield
0060         if numeric_flag(k)
0061             parm.(parm_names{k}) = str2num(input{k});
0062         else
0063             parm.(parm_names{k}) = input{k};
0064         end
0065     end
0066 end

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