legacy_code
이전 댓글 표시
I'd like to use some legacy c with simulink. I've worked through the help but have some questions:
1. How do I add more than one function to an S-function. 2. How do I link a global C variable to a matlab variable r/w - so that I can see what the functions do to the global variable and modify the global from simulink?
답변 (1개)
Kaustubha Govind
2011년 9월 26일
1 개 추천
- You can define any number of functions in an S-function file (or have them in separate C-files that you can link into the S-function binary), as long as you have defined the required mdlXXX functions. What determines the operation of the S-function is where/how you call into the legacy functions. For example, you could call one from mdlInitializeSizes and the other from mdlOutputs, or both from mdlOutputs in whatever order you choose, etc.
- Firstly, note that it is dangerous to use C global variables in an S-function that determine the output, because if you have multiple instances of the S-function in the same model, they can write over each other. The best way to maintain instance-specific data that is accessible to all the mdlXXX methods is to create a DWork variable. Secondly, there is no direct way to link a global C variable to a MATLAB workspace variable. However, you can access the C global variable directly in S-functions, just like you would in any other C code. You could have ssPrintf statements in the S-function mdlXXX methods to print out the value of the variable before/after function calls.
카테고리
도움말 센터 및 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!