How can i save matlab struct / class on level 2 matlab s-function ( like pwork) ? level 2 matlab s-function 에서 구조체 저장하는 방법 (pwork 같이 )

73 views (last 30 days)
Hi all,
I have project written by two version of language ( C or matlab )
And i'm trying to imigrate my project to simulink.
In C s-function, I save struct data in p-work vector simply,
but level2 matlab s-function has no feature like that.
Can you help me?
I think s-function will be more compatible with matlab, why is there a feature only in C?
Is it because of the simplicity of the C data structure?
thank you.
안녕하세요
저는 C / matlab 두가지 언어 버전으로 구현된 프로젝트를 시뮬링크로 이식하고자 합니다.
C s-function에서는 pwork로 간단하게 구조체를 저장할 수 있는데,
matlab s-function 에는 구조체를 저장할수 있는 쉬운 방법이 없는것 같아 질문드립니다.
도움을 받을 수 있을까요?
감사합니다.

Accepted Answer

Broy
Broy on 22 Jan 2026 at 6:32
I understand you are trying to migrate your project from C and MATLAB code into Simulink but are facing an issue where Level-2 MATLAB S-functions lack a P-Work vector feature to store your structural data.
The P-Work vector in C is designed specifically to store pointers to custom C structures. Since MATLAB is a higher-level interpreted language that manages memory automatically, it does not use raw pointers.
To resolve the issue, I recommend using MATLAB System Block Instead of using a Level-2 MATLAB S-function.
Here are some useful Documentations regarding MATLAB System Block as shown below:
I hope this is helpful.
  3 Comments
Haelee
Haelee on 26 Jan 2026 at 7:08
Moved: Stephen23 on 26 Jan 2026 at 7:12
Hi 승욱,
Regarding your comment on the Answer, I assume you can also refer to this MATLAB Answers post: https://www.mathworks.com/matlabcentral/answers/27902-working-with-matlab-classes-in-the-level-2-matlab-s-functions
If you need further assistance, please consider contacting MathWorks Technical Support (https://www.mathworks.com/support/contact_us.html).
Thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2025b

Community Treasure Hunt

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

Start Hunting!