Error using Legacy code: Cannot find a valid lhs expression in the function specification?
Show older comments
** 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 Comments
Jan
on 14 Feb 2017
Did you notice, that your code is not readable? Please consider http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup .
Gaurav Agarwal
on 14 Feb 2017
Walter Roberson
on 19 Jan 2019
the function signature in your h file only has one argument but the function signature in your definition has two parameters .
Answers (1)
Aman Kalia
on 18 Jan 2019
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.
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!