% MUP2MAT converts Mupad string to MATLAB string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: MUP2MAT converts:
% MUP2MAT converts the Mupad string r containing
% matrix, vector, or array to a valid MATLAB string.
%
% NOTE: Copied from the Symbolic Toolbox function sym/matlabFunction
%
% VERSION: $Id: mup2mat.m,v 1.1 2009/05/25 14:14:08 mauro Exp $
%
% HISTORY: 21-05-2009 M Hueller & L Ferraioli
%             Creation
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function r = mup2mat(r)
  
  r = strtrim(char(r));
  % Special case of the empty matrix or vector
  if strcmp(r,'vector([])') || strcmp(r,'matrix([])') || ...
      strcmp(r,'array([])')
    r = '[]';
  else
    % Remove matrix, vector, or array from the string.
    r = strrep(r,'matrix([[','['); r = strrep(r,'array([[','[');
    r = strrep(r,'vector([','['); r = strrep(r,'],[',';');
    r = strrep(r,']])',']'); r = strrep(r,'])',']');
  end
end
