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 comentarios

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

Iniciar sesión para comentar.

Respuestas (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.

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Feb. de 2017

Comentada:

el 19 de En. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by