- "Integrate C Functions Using Legacy Code Tool" : https://www.mathworks.com/help/simulink/sfg/integrating-existing-c-functions-into-simulink-models-with-the-legacy-code-tool.html
- "S-Functions Incorporate Legacy C Code" : https://www.mathworks.com/help/simulink/sfg/example-using-s-functions-to-incorporate-legacy-c-code.html
- "Write Level-2 MATLAB S-Functions" : https://www.mathworks.com/help/simulink/sfg/writing-level-2-matlab-s-functions.html
- "S-Function" block : https://www.mathworks.com/help/simulink/slref/sfunction.html
Help Me in Debugging C Code to S-Function MATLAB
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello Community,
I have .c code file ( for model predictive control) which I received from my professor. That code was written by one of student who is now graduated and I don't have any contact with him.
I am facing problem in compiling that code. I didn't have any experience about C programming language as well as S Function.
After watching few tutorials on Youtube I know how to call using Legacy Tool.
In def.OutputFcnSpec we need to specify our output but unfortunately I am not able to do it and contineously receiving error. I know there is no fault in the code but only mistake I am doing is that I can't able to define the def.OutputFcnSpec correctly.
I have attached the zip file to this question in which I want to compile mpcsolver.c file to use in S-Function block. In the zip file there is .m file which I code to call the legacy function. Please Help me.
댓글 수: 0
답변 (1개)
Sayan
2023년 12월 4일
Hi Muhammad,
I understand from your issue that you need to create a ".mexXXX" (MATLAB executable) file from the source files "mpcsolver.c" and "EKFSolver.c" using the "Legacy Code Tool".
After looking at the source file, I could not find any "add" function, which is specified as "OutputFcnSpec" in the "code_to_call_s_function.m" file for the "Legacy Code Tool." If you are using a handwritten S-function, you still need to define the "add" function and make a call to it from "mdlOutputs".
Alternatively, as you have the "mpcsolver.c" written as "Level-2 MATLAB S-function", you can create the ".mexXXX" without the "Legacy Code Tool" by using the following command:
mex mpcsolver.c
This will create the MATLAB executable, which you can use in the S-Function block to create the desired block in the Simulink model. However, you need to specify the parameters of the S-function in the "S-function parameters" field, separated by comma.
You can find the following documentations on "Integrate C Functions Using Legacy Code Tool" , "S-Functions Incorporate Legacy C Code","Write Level-2 MATLAB S-Functions" and "S-Function" block for more useful information on them.
Hope this helps in resolving the issue.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Block and Blockset Authoring에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!