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 EXT = '.mat'; 0031 file_name = fullfile(PATH, [NAME, EXT]); 0032 0033 num_variable = length(varargin)-1; 0034 0035 compatible_option = vbmeg_saving_version; 0036 0037 % check file existance on caller workspace 0038 exist_command = ['exist(''' file_name ''', ''file'')']; 0039 if evalin('caller', exist_command) 0040 append_mode = '-append'; 0041 else 0042 append_mode = ''; 0043 end 0044 0045 % make save command string 0046 save_command = ... 0047 ['save ' file_name, ' ', ... 0048 append_mode ' ', ... 0049 compatible_option]; 0050 for k=1:num_variable 0051 save_command = [save_command ' ' varargin{k+1}]; 0052 end 0053 0054 % execute save command on caller workspace. 0055 evalin('caller', save_command); 0056 0057 result = SUCCESS;