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

vb_util_show_struct

PURPOSE ^

show all fields of the given struct

SYNOPSIS ^

function vb_util_show_struct(target_struct, rec_flag)

DESCRIPTION ^

 show all fields of the given struct
 [usage]
   vb_util_show_struct(target_struct, rec_flag)
 [input]
   target_struct : <required> <<struct>>
        rec_flag : <optional> flag to read recursively [1]
                 :  1) yes
                 :  0) no
 [output]
   none
 [note]
 [history]
   2010-02-03 (Sako) initial version

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_util_show_struct(target_struct, rec_flag)
0002 % show all fields of the given struct
0003 % [usage]
0004 %   vb_util_show_struct(target_struct, rec_flag)
0005 % [input]
0006 %   target_struct : <required> <<struct>>
0007 %        rec_flag : <optional> flag to read recursively [1]
0008 %                 :  1) yes
0009 %                 :  0) no
0010 % [output]
0011 %   none
0012 % [note]
0013 % [history]
0014 %   2010-02-03 (Sako) initial version
0015 %
0016 % Copyright (C) 2011, ATR All Rights Reserved.
0017 % License : New BSD License(see VBMEG_LICENSE.txt)
0018 
0019 % --- CHECK_ARGUMENTS --- %
0020 if ~exist('target_struct', 'var'), target_struct = []; end
0021 if ~exist('rec_flag', 'var'), rec_flag = []; end
0022 [target_struct, rec_flag] = inner_check_arguments(target_struct, rec_flag);
0023 
0024 if isempty(target_struct)
0025   fprintf('!!!EMPTY!!!\n');
0026   return;
0027 end
0028 
0029 if rec_flag == 0
0030   target_struct
0031   return;
0032 end
0033 
0034 % --- MAIN PROCEDURE --------------------------------------------------------- %
0035 %
0036 % target_struct
0037 if ~isstruct(target_struct)
0038   if isinteger(target_struct)
0039     fprintf('%d\n', target_struct);
0040 
0041   elseif isfloat(target_struct)
0042     fprintf('%f\n', target_struct);
0043 
0044   elseif ischar(target_struct)
0045     fprintf('%s\n', target_struct);
0046 
0047   elseif iscell(target_struct)
0048     n_elm = length(target_struct);
0049     for i_elm = 1:n_elm
0050       fprintf('''%s''\n', target_struct{i_elm});
0051     end
0052   else
0053     fprintf('--- UNEXPECTED TYPE\n');
0054   end
0055   return;
0056 end
0057 
0058 fields = fieldnames(target_struct);
0059 n_field = length(fields);
0060 for i_field = 1:n_field
0061 %   vb_util_show_struct(fields{i_field});
0062   fprintf('\n--- ');
0063   cmd = sprintf('vb_util_show_struct(target_struct.%s)', fields{i_field}); 
0064   fprintf('%s ---\n', cmd);
0065   eval(cmd);
0066 end
0067 return;
0068 %
0069 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0070 
0071 % --- INNER FUNCTIONS -------------------------------------------------------- %
0072 %
0073 % --- inner_check_arguments()
0074 %
0075 function [target_struct, rec_flag] = ...
0076   inner_check_arguments(target_struct, rec_flag)
0077 func_ = mfilename;
0078 if isempty(target_struct)
0079 %   error('(%s) target_struct is a required parameter', func_);
0080 end
0081 
0082 if isempty(rec_flag)
0083   rec_flag = 1;
0084 end
0085 return;
0086 %
0087 % --- end of inner_check_arguments()
0088 %
0089 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0090 
0091 % --- END OF FILE --- %

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