필터 지우기
필터 지우기

Change/reset initial state values in a level 2 C-mex S-function

조회 수: 2 (최근 30일)
Marcus
Marcus 2012년 7월 21일
댓글: Sebastián Gómez Jorge 2023년 8월 2일
Hi all! I'm creating a simulation with level 2 c-mex s-function, and I need to change some state values, when some conditions are verified. How can I do that? I read about the enabled subsystem, but I don't know how it works, and also I don't know if there is something faster that do the same thing.
Can you help me?
Thanks in advance!

채택된 답변

Ryan G
Ryan G 2012년 7월 24일
If you wrote or have the c-code for the s-function you can simply add another input and write a conditional to reset the data when that condition is verified.
  댓글 수: 1
Pan Zhao
Pan Zhao 2017년 6월 22일
I was wondering whether this way really works. I tried this method and met the same problem Michael met (see the answer from Michael below and my comment under that) .

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Michael Walker
Michael Walker 2014년 5월 16일
I have a similar problem, but the evaluation of the variable that triggers the reset is done inside the S-function itself. The problem I'm having is that I can't figure out how to actually reset a continuous state value. Although Simulink seems to let me change the value of variables I fetch with ssGetContStates(S), then next time those state values are needed (again invoking ssGetContStates(S)) they've reverted back to an integrated value of the original initial condition. How do I get this to work?
  댓글 수: 2
Pan Zhao
Pan Zhao 2017년 6월 21일
I have the same problem. Although we can set the ContStates in a S function, they revert to the integrated value of the original initial condition one sampling interval after the setting. Was wondering how we can really reset the states.
Sebastián Gómez Jorge
Sebastián Gómez Jorge 2023년 8월 2일
Same problem and there seems to be no solution. I tired reseting the cont states using the pointer provided by ssGetContStates, but it does not work. The recommended soulution of using an ensabled subsystem is no good, because I want to change the value of only one continuous state when a certain condition happens inside the sfunction. Very frustrating.

댓글을 달려면 로그인하십시오.


Kaustubha Govind
Kaustubha Govind 2012년 8월 2일
You can either follow Ryan's suggestion or put your S-function inside an enabled subsystem with "Output when disabled" set to "reset" - this will call your mdlInitializeConditions method every time the subsystem is disabled.

Marcus
Marcus 2012년 8월 2일
Thanks! By the way now I'm using another method. I stop the simulation with Stop Block and then I start another one. For now it does what I want!

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by