Save variables into mat-file by MATLAB version 6 format. (Append mode) vb_save(filename, 'V', 'XX', ... ) [IN] varargin : variable name string. (varargin{1} = filename) [OUT] result : SUCCESS or FAILURE; Example: vb_save(filename, 'V', 'XX', ... ) Memo: if specified file already exists, variable will be appended to the file. @see vbmeg.m where "vbmeg_saving_version" is set History: ****-**-** (****) initial version 2009-07-06 (Sako) changed specification of the default version Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [result] = vb_save(varargin) 0002 % Save variables into mat-file by MATLAB version 6 format. (Append mode) 0003 % vb_save(filename, 'V', 'XX', ... ) 0004 % [IN] varargin : variable name string. (varargin{1} = filename) 0005 % [OUT] result : SUCCESS or FAILURE; 0006 % 0007 % Example: 0008 % vb_save(filename, 'V', 'XX', ... ) 0009 % Memo: 0010 % if specified file already exists, variable will be appended to the file. 0011 % @see vbmeg.m where "vbmeg_saving_version" is set 0012 % History: 0013 % ****-**-** (****) initial version 0014 % 2009-07-06 (Sako) changed specification of the default version 0015 % 0016 % Copyright (C) 2011, ATR All Rights Reserved. 0017 % License : New BSD License(see VBMEG_LICENSE.txt) 0018 0019 global vbmeg_saving_version 0020 0021 result = FAILURE; 0022 0023 if nargin <= 1, return; end 0024 0025 % extension change to '.mat' 0026 file_name = varargin{1}; 0027 0028 % [PATH, NAME, EXT] = fileparts(file_name); 0029 [PATH, NAME, EXT] = vb_get_file_parts(file_name); 0030 if ~isempty(PATH) && ~exist(PATH, 'dir') 0031 vb_mkdir(PATH); 0032 vb_disp(['Create directory: ' PATH]); 0033 end 0034 0035 EXT = '.mat'; 0036 file_name = fullfile(PATH, [NAME, EXT]); 0037 0038 num_variable = length(varargin)-1; 0039 0040 compatible_option = vbmeg_saving_version; 0041 0042 % check file existance on caller workspace 0043 exist_command = ['exist(''' file_name ''', ''file'')']; 0044 if evalin('caller', exist_command) 0045 append_mode = '-append'; 0046 else 0047 append_mode = ''; 0048 end 0049 0050 % make save command string 0051 save_command = ... 0052 ['save ' file_name, ' ', ... 0053 append_mode ' ', ... 0054 compatible_option]; 0055 for k=1:num_variable 0056 save_command = [save_command ' ' varargin{k+1}]; 0057 end 0058 0059 % execute save command on caller workspace. 0060 evalin('caller', save_command); 0061 0062 result = SUCCESS;