Home > functions > common > utility > vb_matlab_version.m

vb_matlab_version

PURPOSE ^

This function is to know matlab version information.

SYNOPSIS ^

function [varargout] = vb_matlab_version(varargin)

DESCRIPTION ^

 This function is to know matlab version information.
 Usage: [major, minor, revision, build] = vb_matlab_version;
        [comparative_result] = vb_matlab_version('==', '7.0.1');
        [comparative_result] = vb_matlab_version('7.0.1');

 ----- Format1
 To get a version number.

 [major, minor, revision, build] = vb_matlab_version;
 [IN]
     nothing
 [OUT]
     major : MATLAB major version
     minor : MATLAB minor version
     revision : MATLAB revision
     build : MATLAB build number

 ----- Format2
 To Compare with matlab and specified version.
 result = vb_matlab_version('==', '7.0.1');
 [IN]
     comparative_operator : '>' or '<' or '>=' or '<=' or '==' or '~='
     ver_str              : version string separated by '.'
                            ex.'7', '7.0', '7.0.1', '7.0.1.24704'
 [OUT]
     comparative_result : true or false.

 Examples
       If the Matlab version is 7.1.0.83, and the user supplied version is '7':
       status = vb_matlab_version('==', '7');
       returns status == true   : major revision numbers are the same.

       If the Matlab version is 7.1.0.83, and the user supplied version is '7.1':
       status = vb_matlab_version('==', '7.1');
       returns status == true   : major and minor revision numbers are the same.

       If the Matlab version is 7.1.0.83, and the user supplied version is '7.1':
       status = vb_matlab_version('>', '7.1');
       returns status == false   : major and minor revision is later for matlab.

 ---- Format3
 To Compare with matlab and specified version.
 result = vb_matlab_version('7.0.1')
  (This is same with vb_matlab_version('==', '7.0.1');)
 [IN]
     ver_str : version string separated by '.'
               ex.'7', '7.0', '7.0.1', '7.0.1.24704'
 [OUT]
    comparative_result : true or false.

 See also:
     MATLAB embedded function '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 [varargout] = vb_matlab_version(varargin)
0002 % This function is to know matlab version information.
0003 % Usage: [major, minor, revision, build] = vb_matlab_version;
0004 %        [comparative_result] = vb_matlab_version('==', '7.0.1');
0005 %        [comparative_result] = vb_matlab_version('7.0.1');
0006 %
0007 % ----- Format1
0008 % To get a version number.
0009 %
0010 % [major, minor, revision, build] = vb_matlab_version;
0011 % [IN]
0012 %     nothing
0013 % [OUT]
0014 %     major : MATLAB major version
0015 %     minor : MATLAB minor version
0016 %     revision : MATLAB revision
0017 %     build : MATLAB build number
0018 %
0019 % ----- Format2
0020 % To Compare with matlab and specified version.
0021 % result = vb_matlab_version('==', '7.0.1');
0022 % [IN]
0023 %     comparative_operator : '>' or '<' or '>=' or '<=' or '==' or '~='
0024 %     ver_str              : version string separated by '.'
0025 %                            ex.'7', '7.0', '7.0.1', '7.0.1.24704'
0026 % [OUT]
0027 %     comparative_result : true or false.
0028 %
0029 % Examples
0030 %       If the Matlab version is 7.1.0.83, and the user supplied version is '7':
0031 %       status = vb_matlab_version('==', '7');
0032 %       returns status == true   : major revision numbers are the same.
0033 %
0034 %       If the Matlab version is 7.1.0.83, and the user supplied version is '7.1':
0035 %       status = vb_matlab_version('==', '7.1');
0036 %       returns status == true   : major and minor revision numbers are the same.
0037 %
0038 %       If the Matlab version is 7.1.0.83, and the user supplied version is '7.1':
0039 %       status = vb_matlab_version('>', '7.1');
0040 %       returns status == false   : major and minor revision is later for matlab.
0041 %
0042 % ---- Format3
0043 % To Compare with matlab and specified version.
0044 % result = vb_matlab_version('7.0.1')
0045 %  (This is same with vb_matlab_version('==', '7.0.1');)
0046 % [IN]
0047 %     ver_str : version string separated by '.'
0048 %               ex.'7', '7.0', '7.0.1', '7.0.1.24704'
0049 % [OUT]
0050 %    comparative_result : true or false.
0051 %
0052 % See also:
0053 %     MATLAB embedded function 'version'
0054 %
0055 % Copyright (C) 2011, ATR All Rights Reserved.
0056 % License : New BSD License(see VBMEG_LICENSE.txt)
0057 
0058 SEP = '.'; % version separator
0059 
0060 switch(nargin)
0061     case 0 % [major, minor, revision, build] = vb_matlab_version()
0062         [ret] = sscanf(strtok(version), ['%d' SEP], 4);
0063         varargout{1} = ret(1);
0064         varargout{2} = ret(2);
0065         varargout{3} = ret(3);
0066         varargout{4} = ret(4);
0067     case 1 % [comparative_result] = vb_matlab_version('7.0.1');
0068         input_str = varargin{1};
0069         if ~ischar(input_str)
0070             error('version string should be string.');
0071         end
0072         [result] = compare_version('==', input_str, SEP);
0073         varargout{1} = result;
0074     case 2 % [comparative_result] = vb_matlab_version('>=', '7.0.1')
0075         comparative_operator = varargin{1};
0076         input_str = varargin{2};
0077         if ~ischar(input_str)
0078             error('version string should be string.');
0079         end
0080         [result] = compare_version(comparative_operator, input_str, SEP);
0081         varargout{1} = result;
0082 end
0083 
0084 function [result] = compare_version(comparative_operator, ver_str, sep)
0085 
0086 if numel(findstr(ver_str, sep)) > 3
0087     error('Input version string has too many fields. Only major.minor.release.build fields are supported.');
0088 end
0089 
0090 result = true;
0091 
0092 [m_ver] = sscanf(strtok(version), ['%d' sep], 4);
0093 [c_ver, count, errmsg, nextindex] = sscanf(ver_str, ['%d' sep], 4);
0094 if ~isempty(errmsg)
0095     error(['Input version string is invalid at ' num2str(nextindex) ': ' ver_str]);
0096 end
0097 
0098 % Compare
0099 % m_ver(1) m_ver(2) m_ver(3) m_ver(4)
0100 %   |         |        |        |
0101 % c_ver(1) c_ver(2) c_ver(3) c_ver(4)
0102 % ------------> compare direction
0103 %  k==1      k==2     k==3     k==4
0104 for k=1:count
0105     if (m_ver(k) == c_ver(k)) && (k ~= count)
0106         % 最上位桁から下位方向へ向かって1桁ずつチェック
0107         % 同値の場合は、ひとつ下の桁に判断を先送りする。
0108         % 先送りして最下位桁まで行った場合は、
0109         % 同値でも下の比較演算子により比較結果を出力.
0110         continue;
0111     else
0112         % 比較演算子による比較.
0113         result = eval(['m_ver(k)' comparative_operator 'c_ver(k)']);
0114         return;
0115     end
0116 end

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