gpt4 book ai didi

c - "One or more output arguments not assigned during call to "input_4”是什么意思?

转载 作者:太空宇宙 更新时间:2023-11-04 04:45:13 27 4
gpt4 key购买 nike

#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

但是当这个输出值被分配给命令窗口中的一个变量时它说错误..例如

b=input_4(1,2); 3.000000 One or more output arguments not assigned during call to "input_4". why it is not assigning the value of 3 to b. can anyone help me what it means? thanks in advance

最佳答案

您目前没有分配任何 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;
}

关于c - "One or more output arguments not assigned during call to "input_4”是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21829618/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com