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

vb_fsave

PURPOSE ^

Save variables into mat-file by MATLAB version 6 format. (Overwrite mode)

SYNOPSIS ^

function [result] = vb_fsave(varargin)

DESCRIPTION ^

 Save variables into mat-file by MATLAB version 6 format. (Overwrite mode)
   vb_fsave(filename, 'V', 'XX', ... )
 [IN]  varargin : variable name string. (varargin{1} = filename)
 [OUT] result   : SUCCESS or FAILURE;
 
 Example:
  vb_fsave(filename, 'V', 'XX', ... )
 Memo:
  if specified file already exists, the file will be overwritten.
   @see vbmeg.m where "vbmeg_saving_version" is set
   @see vb_save.m
 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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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