Code covered by the BSD License  

Highlights from
SMATLINK - Let Matlab Dance with Mathematica

image thumbnail

SMATLINK - Let Matlab Dance with Mathematica

by

 

04 Jul 2008 (Updated )

Matlab (Frontend) call Mathematica Kernel

SMAT_matlabcall_post_process( input_str )
% /*M-FILE FUNCTION SMAT_MATLABCALL_POST_PROCESS MMM SMATLINK */ %
% /*==================================================================================================
%  Simple MATlab and MAThematica LINK laboratory Toolbox for Matlab 7.x
%
%  Copyright 2009 The SxLAB Family - Yi Chen - leo.chen.yi@gmail.com
% ====================================================================================================
% File description:
%
%          Step 1 : convert string to number, e.g. '3.14' --> 3.14
%          Step 2 : set format to float , NOT 3.14e+00
%          
%Exampe:
%1)
% [ output_str ] = SMAT_matlabcall_post_process( '{3.14e+00}' )
% 
% output_str =
% 
%              3.1400
%2)
% [ output_str ] = SMAT_matlabcall_post_process( '{-1.83067*^5}' )
% 
% output_str =
% 
%      -183067
%===================================================================================================
%  See Also:        
%                    
%                    SMAT_matlabcall_casetest.m  
%                    SMAT_matlabcall_demo_script.m
%===================================================================================================
% 
% 
%===================================================================================================
%Revision -
% Date         Name                    Description of Change
% 29-Jun-2008  Yi Chen                 Initial
%HISTORY$
%==================================================================================================*/

% SMAT_MATLABCALL_POST_PROCESS Begin

function [ output_str ] = SMAT_matlabcall_post_process( input_str )

%Step 1: check input string
% check '*^'
 input_str  = SMAT__matlabcall_check_input_type_1( input_str );

%Step 2: take out '{' and '}' in string of '{ ***** }'
% check '{}'
 input_str  = SMAT__matlabcall_check_input_type_2( input_str );
 
 
%Step 3: take out '{' and '}' in string of '{ ***** }'
% check '\012' or '\015'
 output_str  = SMAT__matlabcall_check_input_type_3( input_str );
 
%Step 4 : convert number to string, e.g. 3.14 --> '3.14'
% output_num = str2double( input_str  );
% output_num = str2num(input_str);

%this is not necessary, only when you need the line 
% output_str = str2num(output_str);

%  Step 5 : set format to float , NOT 3.14e+00
% format long g

% SMAT_MATLABCALL_POST_PROCESS End


% *************************************************************************
% Sub functions
% *************************************************************************
% strcmp('Yes', 'No')
% ans =
%      0
% strcmp('Yes', 'Yes')
% ans =
%      1

function [ output_string ] = SMAT__matlabcall_check_input_type_1( input_string )
% '*^'
% strcmpi( findstr('{-1.8*^7}','*^') ,'[]' ) 
tem = strcmpi( findstr(input_string,'*^') ,'[]' );

     if (  tem == 0 )  % '*^ exist in this string'
%       strrep('{-1.8*^7}', '*^', '*10^')
        output_string = strrep(input_string, '*^', '*10^');
     else
         output_string = input_string;
     end
     
     
function [ output_string ] = SMAT__matlabcall_check_input_type_2( input_string )
% '{}'

input_string = regexprep(input_string, '{', '');

output_string = regexprep(input_string, '}', '');

% % strcmpi( findstr('{-1.8*^7}','*^') ,'[]' ) 
% tem = strcmpi( findstr(input_string,'{') ,'[]' );
% 
%      if (  tem == 0 )  %  '{ exist in this string'
%          output_string = input_string( 2:size( input_string , 2 )-1 );
%      else
%          output_string = input_string;
%      end
     
     
function [ output_string ] = SMAT__matlabcall_check_input_type_3( input_string )
%[ output_string ] = SMAT__matlabcall_check_input_type_3( ' 5\012x ' )
% '\012 or \015' = '\n'
% strcmpi( findstr(' 5\012x ','\012') ,'[]' ) 
tem = strcmpi( findstr(input_string,'\012') ,'[]' );

     if (  tem == 0 )  % '\012 exist in this string'
        output_string = strrep(input_string, '\012', '\r');
     else
        output_string = input_string;
     end

Contact us