當前位置:首頁 » 編程軟體 » mex編譯

mex編譯

發布時間: 2022-06-01 08:31:44

『壹』 用mex編譯.c文件怎麼指定.c文件要包含的頭文件

mex Compile mex-function

Usage:
mex [options ...] file [files ...]

Description:
mex compiles and links source files into a shared library called a
mex-file, executable from within MATLAB. It also builds executable
files for standalone MATLAB engine and MAT-file applications.

Command Line Options Available on All Platforms:
-c
Compile only. Creates an object file but not a mex-file.
-client engine
Build standalone MATLAB engine or MAT-file application.
-compatibleArrayDims
Build a mex-file using the MATLAB Version 7.2 array-handling
API, which limits arrays to 2^31-1 elements. This option is the
default, but in the future the -largeArrayDims option will be
the default.
-D<name>
Define a symbol name to the C preprocessor. Equivalent to a
"#define <name>" directive in the source. Do not add a space
after this switch.
-D<name>=<value>
Define a symbol name and value to the C preprocessor. Equivalent
to a "#define <name> <value>" directive in the source. Do not
add a space after this switch.
-f <optionsfile>
For advanced users. Specify location and name of the mex
configuration file to use. Overrides mex's default compiler
selection mechanism.
-g
Create a mex-file containing additional symbolic information for
use in debugging. This option disables mex's default behavior of
optimizing built object code (see the -O option).
-h[elp]
Display this message.
-I<pathname>
Add <pathname> to the list of directories to search for #include
files. Do not add a space after this switch.
-l<name>
Link with object library. On Windows, <name> expands to
"<name>.lib" or "lib<name>.lib". On Linux, to "lib<name>.so".
On Mac, to "lib<name>.dylib". Do not add a space after this
switch.
-L<folder>
Add <folder> to the list of folders to search for
libraries specified with the -l option. Do not add a space
after this switch.
-largeArrayDims
Build a mex-file using the MATLAB large-array-handling API. This
API can handle arrays with more than 2^31-1 elements when
compiled on 64-bit platforms. -compatibleArrayDims is the
default option.
-n
No execute mode. Display commands that mex would otherwise
have executed, but do not actually execute any of them.
-O
Optimize the object code. Optimization is enabled by default and
by including this option on the command line. If the -g option
appears without the -O option, optimization is disabled.
-outdir <dirname>
Place all output files in folder <dirname>.
-output <resultname>
Create mex-file named <resultname>. The appropriate mex-file
extension is automatically appended. Overrides mex's default
mex-file naming mechanism.
-setup <lang>
Change the default compiler to build <lang> language mex-files.
When this option is specified, no other command line
input is accepted.
-silent
Suppress informational messages. The mex function still reports
errors and warnings, even when you specify -silent.
-U<name>
Remove any initial definition of the C preprocessor symbol
<name>. (Inverse of the -D option.) Do not add a space after
this switch.
-v
Verbose mode. Display the values for important internal
variables after all command line arguments are considered.
Displays each compile step and final link step fully evaluated.
<name>=<value>
Override default setting for variable <name>. This option is
processed after all command line arguments are considered.

Command Line Options Available Only on Windows Platforms:
@<rspfile>
Include contents of the text file <rspfile> as command line
arguments to mex.

『貳』 mex文件的MEX的編寫

mex的編譯結果實際上就是一個帶輸出函數mexFunction 的dll文件,所以寫MEX程序其實就是寫一個DLL程序。編寫MEX程序的編輯器可以使用MATLAB的代碼編輯器,也可使用自己的C++編輯器,如VS2008等。 #includemex.hvoidmexFunction(intnlhs,mxArray*plhs[],intnrhs,constmxArray*prhs[]){}四個參數分別用來輸出和輸入數據: nlhs 是輸出參數個數,plhs 是輸出參數指針;nrhs 是輸入參數個數,prhs 是輸入參數指針。
注意: 對輸出和輸入參數的操作都是通過指針的方式進行的。 對輸入數據進行操作,需要通過MEX函數mxGetPr 得到數據的指針地址。 mxGetM 和 mxGetN 得到矩陣數據的行和列 (返回整數)。對於實矩陣,我們可以定義 double *M; 來對實矩陣數據操作。如: double*M;intm,n;//指針指向第一個參數的數據地址M=mxGetPr(prhs[0]);m=mxGetM(prhs[0]);n=mxGetN(prhs[0]);MATLAB矩陣數據的存儲順序是從上到下,從左到右的,這點和Fortran是一樣的。也就是說對於MATLAB的m x n的矩陣A。 A(1,1) 就是 *M,A(2,1) 就是 *(M+1) ,以此類推,A(i,j) 就是 *(M + n*(j-1) + (i-1)).
注意: MATLAB的指標從1開始,C的指標從0開始。 創建文件 timestwoalt.c,其內容如下: #includemex.hvoidtimestwo_alt(double*y,doublex){*y=2.0*x;}voidmexFunction(intnlhs,mxArray*plhs[],intnrhs,constmxArray*prhs[]){double*M;intm,n;//指針指向第一個參數的數據地址M=mxGetPr(prhs[0]);m=mxGetM(prhs[0]);n=mxGetN(prhs[0]);plhs[0]=mxCreateDoubleMatrix(m,n,mxINT32_CLASS,mxREAL);//生成mxn的實矩陣,分配內存空間double*A;A=mxGetPr(plhs[0]);timestwo_alt(A,*M);//調用並直接賦值到指針指向的輸出變數}

『叄』 什麼是Mex文件

MEX文件是一種可在matlab環境中調用的C語言(或fortran)衍生程序,mex的編譯結果實際上就是一個帶輸出函數mexFunction 的dll文件。

『肆』 matlab 中mex -setup 編譯器怎麼弄

這個需要你的電腦上安裝有C++6.0才能出來,mex -setup列出的編譯器都是你電腦上的,你圖上的[1] Lcc-win32是matlab自帶的編譯器。
由於你電腦上沒安裝其他的編譯器,當然就檢測不到C++6.0

『伍』 matlab如何編譯mex文件

通過MEX文件可以在MATLAB中像調用內嵌函數一樣調用現有的使用C語言和Fortran等語言編寫的函數,實現了代碼重用,同時也能解決MATLAB循環效率低的缺點,提高MATLAB環境中數據處理的效率。
MEX文件的後綴名為 .mexw32
MEX文件的編寫和編譯需要兩個基本條件:一是必須按照MATLAB應用程序介面組件和相關工具,二是要有C語言或Fortran語言的編譯器。
需要對MATLAB系統進行設置,使MATLAB系統知道使用系統的哪一個C語言編譯器,以及其參數和路徑。
MEX文件系統設置:
>> mex –setup按照提示進行,最後出現Done…系統配置完畢。
C語言MEX文件的建立
C語言MEX文件的建立
1. MEX文件的結構
a) 計運算元程序
b) 入口子程序,void mexFunction(int nlhs, mxArray *plhs[],int nrhs,const mxArray *prhs[]){ /*用戶特定的代碼….*/ }
2. 創建timestwoalt.c
#include "mex.h"
void timestwo_alt(double *y, double x)
{
*y = 2.0*x;
}
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double *y;
doublex;
/* 檢查參數 */
if (nrhs != 1) {
mexErrMsgTxt("One input argument required.");
} else if (nlhs > 1) {
mexErrMsgTxt("Too many output arguments.");
} else if (!mxIsNumeric(prhs[0])) {
mexErrMsgTxt("Argument must be numeric.");
} else if (mxGetNumberOfElements(prhs[0]) != 1 || mxIsComplex(prhs[0])) {
mexErrMsgTxt("Argument must be non-complex scalar.");
}
/* 為輸出參數創建變數 */
plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
/*
為參數 x、y賦值,x為值,而y為指針
(由於MATLAB沒有值傳遞,所以用指針才能得到修改後的y值,
不然修改的是y的一個副本,為臨時變數,在函數返回時,y值沒有變化,
不能得到希望的結果)
*/
x = mxGetScalar(prhs[0]);
y = mxGetPr(plhs[0]);
/* 調用timestwo_alt 子函數 */
timestwo_alt(y,x);
}
3. 編譯鏈接C語言的MEX文件源程序,在MATLAB的控制窗口中輸入:mex timestwoalt.c生成一個名為timestwoalt.mexw32的MEX文件
4. 運行:在MATLAB的控制窗口中輸入
x=2;
y=timestwoalt(x)
輸出:y=4
MEX文件實現了一種C語言與MATLAB的介面,其實際的計算功能仍在C語言形式的計運算元程序中完成,而入口子程序的功能是檢查參數以匹配C語言的參數規范(how to?)。
當有C語言編寫的大型程序時,不必用MATLAB語言重新編寫,只要將此C語言程序作為一個計運算元程序,然後編寫一個入口子程序,完成參數的匹配,然後編譯成MEX文件即可。
MEX文件的另外一個功能是可以將MATLAB編程中的瓶頸問題,如多重循環等,將此類費時的指令用C語言實現,然後作必要的入口子程序,編譯成MEX文件,可以有效地提高MATLAB的效率。
S-函數創建器限制了C語言S-函數的功能:只能有一個輸入信號和一個輸出信號,而且只能處理double類型的數據!所以,可用性不大。

『陸』 請教關於利用Matlab中「mex」命令編譯C程序的問題

1.准備好C語言程序,清楚C語言的入口函數
2.編寫mexfunction函數。mexfunction函數為C語言與MATLAB語言的介面函數。調用實例在mylinedetect.c文件中.在MATLAB中調用mex指令編譯相關文件,將C語言編譯為MEX文件。
3.編譯完成後,生成mylinedetect.mexw32或mylinedetect.mexw64文件,此文件即mex文件,用於MATLAB與C語言介面函數.
4.編譯完成之後,編寫MATLAB函數,調用MEX文件。以MEX文件的形式調用編譯完成的C語言函數[o1,o2]=mylinedetect(double(X).');......
5.輸出結果,上述linedetect函數完成圖像中直線檢測功能,帶入MATLAB中調用後形成結果。

『柒』 MATLAB mex 找不到編譯器怎麼辦

①選y後,MATLAB會列出當前機器上已經安裝的、且與當前MATLAB版本兼容的所有C編譯器,一般而言,MATLAB都會自帶一個LCC編譯器,然而LCC目前僅支持32位的MATLAB,所以你的機器上沒有。

②選n後,MATLAB會列出所有與當前MATLAB版本兼容的C編譯器類型(不管你是否已經安裝,用於幫助用戶選擇合適的C編譯器),你機器上已經安裝的2個編譯器,VC6.0:MATLAB從R2010b之後不再支持,所以選項里看不到;而SDK7.1選n時可以看到([11]),但選y時沒有跳出,是因為MATLAB沒有正確定位SDK。

③解決方法:

方法一:如果以預設選項安裝了SDK7.1(不改變默認安裝路徑),可以嘗試輸入n後,選擇 [14] (注意:是14,不是11!),強制定位該編譯器(網上有人用這種方法成功了:http://mlinking.blog.163.com/blog/static/185801922201331464626365/)

方法二:重新安裝MATLAB,安裝時選擇32位進行安裝,則自帶LCC編譯器。

方法三:選擇適配的VS版本,下載安裝後,重新配置MEX命令。

『捌』 mex是什麼意思

MEX從字面上是MATLAB和Executable 兩個單詞的縮寫

MEX文件是一種可在matlab環境中調用的C語言(或fortran)衍生程序,mex的編譯結果實際上就是一個帶輸出函數mexFunction 的dll文件。

MEX文件實現了一種其它語言與MATLAB的介面,通過MEX文件可以在MATLAB中像調用內嵌函數一樣調用使用C語言和Fortran等語言編寫的函數,實現了代碼重用,同時也能提高MATLAB環境中數據處理的效率。

MEX的編寫

mex的編譯結果實際上就是一個帶輸出函數mexFunction 的dll文件,所以寫MEX程序其實就是寫一個DLL程序。編寫MEX程序的編輯器可以使用MATLAB的代碼編輯器,也可使用自己的C++編輯器,如VS2008等。

『玖』 mex文件的MEX的編譯

如編譯鏈接C語言的MEX文件源程序,在MATLAB的控制窗口中輸入:mex timestwoalt.c生成一個名為timestwoalt.mexw32的MEX文件

『拾』 mex編譯C++,能否使用cout等函數

不能。
mexPrinf是專門用於列印調試信息的介面。調試信息就用這個函數輸出。
如果函數本身有I/O需求,比較好的方法是只用C寫I/O無關的計算部分,I/O部分還是用matlab寫。

熱點內容
安卓微信流量怎麼控制 發布:2024-05-04 12:47:19 瀏覽:797
mysql主從復制資料庫 發布:2024-05-04 12:37:55 瀏覽:510
開公司人員配置不夠有什麼影響 發布:2024-05-04 12:32:21 瀏覽:433
rust網路編程和ftp 發布:2024-05-04 12:32:21 瀏覽:61
微信怎麼知道賬號密碼 發布:2024-05-04 12:20:06 瀏覽:977
我的世界伺服器如何用自己的存檔 發布:2024-05-04 12:06:36 瀏覽:337
七日殺伺服器ip怎麼設置 發布:2024-05-04 11:57:57 瀏覽:431
啟用java 發布:2024-05-04 11:51:46 瀏覽:970
mac下開發php 發布:2024-05-04 11:28:53 瀏覽:628
java介面及實現方法 發布:2024-05-04 11:05:08 瀏覽:567