簡體   English   中英

錯誤消息Mex文件Matlab

[英]Error Message Mex file Matlab

在此錯誤消息之前是否有任何人:

未定義的函數或方法'函數名'用於輸入“double”類型的參數。

編譯mex文件時,我總是有這個錯誤消息。 我已經檢查了很好的路徑,它似乎是正確的。

這是我的代碼,mex文件是amortiss.c

#include "mex.h"

/* The computational functions */
void arrayquotient(double input1, double input2, double output1)
{

   output1=input1/input2;

}


/* The gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[])
{
/* variable declarations here */
    double input1;      /* input scalar 1 */
    double input2;       /* input scalar 2*/
    double output1;      /* output scalar 1 */   

/* code here */
    /* get the value of the scalar input1  */
   input1 = mxGetScalar(prhs[0]);

/* get the value of the scalar input2 */
   input2 = mxGetScalar(prhs[1]);

/* get the value of the scalar input3 */
   input3 = mxGetScalar(prhs[2]);

/* create the output scalar1 */
    plhs[0] = mxCreateDoubleScalar(input1/input2);

/* get the value of the scalar output1 */
   output1 = mxGetScalar(plhs[0]);

/* call the computational routines */
arrayquotient(input1,input2,output1);
}

我添加路徑(命令添加路徑),以確保MEX文件amortiss.c存在。 然后我創建了一個名為arrayquotient.m的.m文件,其中我剛剛寫了我的函數聲明:

function c = arrayquotient(a,b)

但是,在編譯時,會出現另一條錯誤消息:

Error in ==> arrayquotient at 1
function c=arrayquotient(a,b)

??? Output argument "c" (and maybe others) not assigned during call to
"C:\Users\hp\Documents\MATLAB\codes_Rihab\arrayquotient.m>arrayquotient".

函數amortiss.c是一個c文件,不能由Matlab按原樣執行。
您創建的文件arrayquotient.m是一個空函數,它不為其輸出c賦值。

你需要做的是MEX的c文件amortiss.c創建MEX文件amortiss.mexw32 (擴展根據您的體系結構有所不同。用mexext找出你應該尋找擴展名)。

在matlab中,設置你的mex編譯器:

>> mex -setup

您將被指示從編譯器中選擇安裝您的機器並由Matlab識別。

一旦你設置了mex編譯器,你就可以繼續使用c-file

>> mex -O -largeArrayDims amortiss.c

那么你將有一個mex文件amortiss.mexXXX ('XXX'取決於你的架構)。
您可以像任何其他功能一樣使用該功能

>> c = amortiss( a, b );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM