Matlab code to C + + code conversion and use of the full guide

Source: Internet
Author: User

1. Enter the command in MATLAB:

Mbuild-setup Install the compiler. (Note: Select the Vc/vs compiler already on your computer and enter the appropriate path)

2. Enter the command in MATLAB:

Deploytool Enter this mode

3. Press the New button, select the C + + Shared Library, name the project, and select the path. Then add files and choose the M file that will be converted. Finally, build the project and compile the M file. After the compilation succeeds, the code is generated under the Distrib folder in the specified directory. This folder generates a DLL file, a header file, and a Lib file. (note here that Matlab is divided into 32-bit version and 64-bit version, with the corresponding version of MATLAB follow this process to generate the corresponding version of the DLL files and Lib files. So, when calling in VS, adjust to the appropriate version. For example, the DLL and LIB files generated with 64-bit MATLAB should be run under the x64 platform in VS, otherwise the link error will be generated. To pay attention to the unity of the platform, some controls in VS, such as the Comm control only support 32-bit, so in order to use the same, the front also use 32-bit MATLAB)

4. Copy the files generated by step 3rd to the VS project.

Copy the Include folder under Matlab/extern to the project of VS and add it to the include directory of the VC + + directory.

Copy the Libmat.lib,mclmcr.lib,mclmcrrt.lib under Matlab/extern/lib/win64/microsoft to the VS project and add these libraries to the linker/input/Additional dependencies .

5. Call the DLL in the code.

(1) Initializing library mclinitializeapplication (null,0)

Xxxinitialize () xxx for the 3rd step generate file name

(2) operation of the Mwarray

such as Matlab China noise canceling function Wden (IN1,IN2,IN3,IN4,IN5,IN6);

This translates into the following:

extern lib_wden_cpp_api void Mw_call_conv wden (int nargout, mwarray& xd, mwarray& cxd, mwarray& lxd, const MwA rray& in1, const mwarray& in2, const mwarray& in3, const mwarray& in4, const mwarray& IN5, const Mwarr ay& in6);

Nargout ——— The number of output variables

xd--signal after the output variable has been eliminated

cxd--output variable xd Qi Xiaobo

lxd--output variable xd Qi Xiaobo

in1--Input Variable raw signal

in2-- input Variable threshold selection rule selectable mode: ' Rigrsure ', ' heursure ', ' sqtwolog ', ' Minimaxi '

in3-- input variable soft threshold or hard threshold selectable mode: ' s ' or ' H '

in4-- Input Variable threshold scale change selectable mode:' one ', ' sln ', ' mln '

in5-- The number of layers of the input variable wavelet transform

in6-- input variable wavelet type such as ' DB10 ', ' SYM8 '

Example: to Implement Xd_filter = Wden (XD, ' Minimaxi ', ' s ', ' mln ', 5, ' DB10 '); The code is as follows:

const int datanum = 5500;        Char str1[9] = "Minimaxi"; char str2[2] = "s"; char str3[4] = "mln"; int  STR4 = 5;char str5[5] = "DB10"; Mwarray Str1 (str1 ); Mwarray Str2 (STR2); Mwarray Str3 (STR3); Mwarray STR4 (STR4); Mwarray STR5 (STR5); Mwarray XD (Datanum, 1, mxdouble_class); Mwarray Xd_filter (Datanum, 1, mxdouble_class); Mwarray cxd (datanum,1, mxdouble_class); Mwarray lxd (datanum,1, mxDOUBLE_ CLASS); Xd. SetData (in, Datanum); Wden (1, Xd_filter, Cxd, Lxd, XD, Str1, STR2, STR3, STR4, STR5); Xd_filter. GetData (out, datanum);

(3) In order to be convenient for later use, the class of the project can be further written into the DLL form.

Matlab code to C + + code conversion and use of the full guide

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.