from
SMATLINK - Let Matlab Dance with Mathematica
by Yi Chen
Matlab (Frontend) call Mathematica Kernel
|
| SMAT_matlabcall_demo_function( x , y )
|
% /*M-FILE FUNCTION SMAT_MATLABCALL_DEMO_FUNCTION 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:
%
% An example for Calling Mathematica Kernel by Matlab Function m-file
%
% z = sqrt( x^2 + y^2 )
%Exampe:
% 1)
% z = SMAT_matlabcall_demo_function( 3.1 , 4.1 )
%
% z =
%
% 5.14003891035856
%2)
% z = SMAT_matlabcall_demo_function( 3 , 4 )
%
% z =
%
% 5
%===================================================================================================
% 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_DEMO_FUNCTION Begin
function [ z ] = SMAT_matlabcall_demo_function( x , y )
% Step 1 : Pro process - convert number to string by num2str()
aa = SMAT_matlabcall_pre_process( x^2 );
bb = SMAT_matlabcall_pre_process( y^2 );
% Step 2 : build a input string
input = [ aa, '+', bb ];
% Step 3 : define a function in mathematica
output = SMAT_matlabcall(input);
% Step 4 : Post process - convert string output to number output by str2num()
% str2double()
z = sqrt(SMAT_matlabcall_post_process( output ));
% Step 5 : Optional
SMAT_matlabcall('Close')
% SMAT_MATLABCALL_DEMO_FUNCTION End
|
|
Contact us at files@mathworks.com