久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Visual Studio創(chuàng)建Matlab mex(dll)函數(shù)

 maoj66 2014-04-11

本文主要介紹在Windows XP 32bit操作系統(tǒng)下,利用Visual Studio 2005,,如何生成Matlab可執(zhí)行的mex(dll)文件,。(1). 首先,使用Visual Studio 2005編譯生成動(dòng)態(tài)鏈接庫(kù)dll文件,。(2). 然后,,在Matlab 2009b中調(diào)用生成的mex(dll)文件。


   1). 打開Visual Studio 2005,,建立一個(gè)Win32 Project,,項(xiàng)目名為test_matlab_3

Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)
   2). 項(xiàng)目類型設(shè)定時(shí)選擇DLL,并選定Export symbol和Empty project,,注意要先選Export symbol再選Empty project,。Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)
   3). 然后打開project -> add new item,添加C++ file 文件名為mexFunction.cpp,。文件代碼后附,。
Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)
   4). 然后打開tool -> option -> Projects and Solutions -> VC++ Directories -> Include files 增加matlab頭文件目錄地址。"C:\Program Files\MATLAB\R2009b\extern\include",。由于最近經(jīng)常使用matlab,,就把頭文件目錄添加到VC設(shè)置中。如果只是偶爾使用matlab,可以把頭文件目錄加到project -> test_matlab_3 properties -> C++ -> General -> Additional Include Directories 中,。Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)
   5). 然后打開tool -> option -> Projects and Solutions -> VC++ Directories -> Library files 增加matlab庫(kù)文件目錄地址,。"C:\Program Files\MATLAB\R2009b\extern\lib\win32\microsoft"。如果只是偶爾使用matlab,,可以把庫(kù)文件目錄加到project -> test_matlab_3 properties -> Linker -> General -> Additional Library Directories 中,。
Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)
   6). 然后打開project -> test_matlab_3 properties -> C++ -> Preprocessor 添加 TEST_MATLAB_3_EXPORTS。
Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)

 
   7). 然后打開project -> test_matlab_3 properties -> C++ -> Code Generation -> Runtime Library,,選擇 Multi-threaded Debug (/MTd),。Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)
   8). 然后打開project -> test_matlab_3 properties -> Linker -> Input -> Additional Dependencies中添加 libmx.lib,libmat.lib,,libmex.lib,,libeng.lib。Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)


    9). 然后打開project -> test_matlab_3 properties -> Linker -> Input -> Module Definition File中添加 .\mexFunction.def,。Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)


    10). 然后打開project -> add new item,,添加Module-Definition File 文件名為mexFunction.def。文件代碼后附,。Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)

    11). 然后打開project -> add new item,,添加Header File 文件名為mexFunction.h。文件代碼后附,。Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)


    12). 編譯,,鏈接,生成test_matlab_3.dll文件,,也就是我們想要的mex文件,。

    13). 將生成的文件拷貝到matlab目錄下,執(zhí)行"test_matlab_3(1,'Panpan Hu')",,返回如下結(jié)果Visual <wbr>Studio創(chuàng)建Matlab <wbr>mex(dll)函數(shù)

注意:本質(zhì)上來(lái)講mex和dll沒有區(qū)別,,只是兩個(gè)不同的后綴名。Matlab2010b以后版本可能不支持調(diào)用dll為后綴的mex文件,。消息來(lái)源如下

http://www./help/techdoc/matlab_external/bsehn8g.html

A MEX-file is a shared library dynamically loaded at runtime. Shared libraries are sometimes called .dll files, for dynamically-linked library. MEX-files have a platform-dependent extension, which the mex function automatically assigns.

On 32-bit Windows platforms, the extension is .mexw32. MATLAB has supported .dll as a secondary MEX-file extension since Version 7.1 (R14SP3). In Version 7.7 (R2008b), if you used the -output switch to create a MEX-file with a .dll extension, MATLAB displayed a warning message that such usage is being phased out.

In MATLAB Version 7.10 (R2010a), you can no longer create a MEX-file with a .dll file extension. If you try to, MATLAB creates the MEX-file with the proper extension and displays the following warning:

Warning: Output file was specified with file extension, ".dll", which
         is not a proper MEX-file extension.  The proper extension for
         this platform, ".mexw32", will be used instead. 

MATLAB continues to execute a MEX-file with a .dll extension, but future versions of MATLAB will not support this extension.


本文參考如下網(wǎng)絡(luò)資源

http://blog.sina.com.cn/s/blog_4d1865f00100o2ul.html

http://www.engineering./~dip/lecture/C++_with_Matlab.pdf


附錄1 mexFunction.cpp

#include "mexFunction.h"
#include <string>
#include "stdlib.h"
#include <iostream>
using namespace std;
void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray*prhs[] )
{
    double *Encoder_Decoder_db = NULL;
    string Path_Str="";     // the path of the bands
    unsigned int bufferlength = mxGetM(prhs[1])*mxGetN(prhs[1])+1;
    char *Path_Str_ch = new char[bufferlength];
    short Encoder_Decoder;  // 0: encoder, 1: decoder
    Encoder_Decoder_db = mxGetPr(prhs[0]);
    mxGetString(prhs[1], Path_Str_ch, bufferlength); 
    Encoder_Decoder = (short) *Encoder_Decoder_db;
    Path_Str = Path_Str + Path_Str_ch;
    mexPrintf("\nBegin of Test-Zhao Wang 6.2.2011\n");
    mexPrintf("%d, %s\n", Encoder_Decoder, Path_Str_ch);
    mexPrintf("End of Test-Zhao Wang 6.2.2011\n");
}


附錄2 mexFunction.h

#include "matrix.h"
#include "mex.h"
#define TEST_MATLAB_3_EXPORTS
#ifdef TEST_MATLAB_3_EXPORTS
#define MEX_FUNCTION_API __declspec(dllexport)
#else
#define MEX_FUNCTION_API __declspec(dllimport)
#endif
MEX_FUNCTION_API void mexFunction(int nlhs, mxArray* plhs[],int nrhs, mxArray* prhs[]);


附錄3 mexFunction.def

LIBRARY    "test_matlab_3"
EXPORTS
        mexFunction

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多