Error using Legacy code: Cannot find a valid lhs expression in the function specification?

** Error using legacycode.LCT.legacyCodeImpl
> legacy_code('sfcn_cmex_generate', def);
after I use the command to generate sfunction i get the above error:*
Source File:
#include "Controller.h"
double Cout, X;
double controller(double Pout, double Pin)
{
if(Pout>0)
Cout = -X/2;
else
Cout = X/2;
return Cout;
}
Header File:
#ifndef _CONTROLLER_H_
#define _CONTROLLER_H_
double contr(double Pout);
#endif
| *
def.SourceFiles = {'Controller.c'};
def.HeaderFiles = {'Controller.h'};
def.SFunctionName = 'ex_sfun_controller';
def.OutputFcnSpec = 'double y = controller(double u1,double u2)';
legacy_code('sfcn_cmex_generate', def);*|
How to resolve this error?

댓글 수: 3

the function signature in your h file only has one argument but the function signature in your definition has two parameters .

댓글을 달려면 로그인하십시오.

답변 (1개)

Hey Gaurav,
I was running into the same issue and found the error I was making. In your def.OutputFcnSpec you need to make sure that output and input variables are represented correctly. In your case, replace def.OutputFcnSpec in your code with the following:
def.OutputFcnSpec = 'double y1 = controller(double u1,double u2)';
Basically change y to y1 and it should work. For passing parameters use p1, p2 , p3 and so on.
Hope this helps.

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

질문:

2017년 2월 14일

댓글:

2019년 1월 19일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by