After referring to the articles shared by everyone on the Internet and some books about the joint simulation methods of OPNET and MATLAB, I finally tried it. Now I will share the process with his family and learn and exchange it together ~
The main process is as follows:
- Configure the OPENT environment: in Edit --> preference: (My MATLAB is installed in the root directory of drive D)
L Complication settings
Add/ID: MATLAB/extern/include to Comp_flags_common. Here D:/MATLAB is the installation directory of MATLAB. This setting can make the compiler contain some necessary MATLAB header files.
L Link settings
Add the value/LIBPATH: "D:/MATLAB/extern/lib/win32/microsoft/msvc60" to the Bind_shobj_flag variable. Set the value of Bind_shobj_lib to libmx. lib.
Libmat. lib libeng. lib. With this setting, OPNET can call the MATLAB Engine function library.
L environment variable settings:
Include: D:/MATLAB/extern/include;
Add D:/MATLAB/extern/Lib/win32/microsoft in lib;
Add D:/MATLAB/bin/win32 to PATH.
2. Programming Guide
1) Add the header file # include "engine. h" to open the computing engine ep = engOpen ();
2) define variables in OPNET, such as double * t;
3) define the data structure mxArray * T of the mx interface of MATLAB and create a matrix. Use the function T = mxCreateDoubleMatrix (, mxREAL) to create a real matrix of three rows and two columns;
4) convert the value of double * t to T and use the statement memcpy (mxGetPr (T), t, 6 * sizeof (double ));
5) introduce T in OPNET into the MATLAB Workspace: Use the function engPutVariable (ep, "T", T), where ep is Engine * ep;
6) perform MATLAB calculations. Use the engEvalString function to execute simple MATLAB commands such as engEvalString (ep, "polt (T, T )"); you can also execute functions in a custom m file, such as engEvalString (ep, "path (path,'m file path ')"); engEvalString (ep, "m file functions ");
7) if a return value exists, use the function to receive the returned value mxArray * T1 = engGetVariable (ep, "T ");
8) convert the returned values to the Data Type in OPNET, for example, double * t1. Use the function t1 = (double *) mxGetData (T1 );
9) destroy all mxArray data. Use the function: mxDestroyArray (T );
10) disable the computing engine engClose (ep );
All of this allows you to complete the joint simulation of OPNET and MATLAB ~~~~