#include "mex.h"
#include "string.h"
void mexFunction( int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
double out, out_1, out_2;
out_1 = mxGetScalar(prhs[0]);
out_2 = mxGetScalar(prhs[1]);
out= out_1+out_2;
mexPrintf("%f\n ", out);
return;
}我写了这个函数来和这两个数字。啊,真灵。
mex input_4.c input_4(1,2) 3.000000
但是,当这个输出值被分配给命令window..for示例中的一个变量时,它表示错误。
b=input_4(1,2);3.000000个在调用"input_4“时未分配的一个或多个输出参数。为什么不将3的值分配给b ?有人能帮助我吗?提前感谢
发布于 2014-02-26 14:49:43
您目前没有分配任何输出,MATLAB将识别。您需要将输出分配给plhs。我会这样做:
void mexFunction( int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
double out, out_1, out_2;
out_1 = mxGetScalar(prhs[0]);
out_2 = mxGetScalar(prhs[1]);
out= out_1+out_2;
if (nlhs == 1)
plhs[0] = mxCreateDoubleScalar(out);
else if (nlhs > 1)
mexErrMsgIdAndTxt("mexFile:tooManyOutputs", "Too many outputs!");
else
mexPrintf("%f\n ", out);
return;
}发布于 2014-02-17 13:28:57
我认为这是因为您的函数返回类型是void。它没有归还任何东西。您看到的输出是由printf打印的,您的函数没有返回它。
尝试返回您计算的值。
https://stackoverflow.com/questions/21829618
复制相似问题