S-Function: Inital Value as Output

조회 수: 1 (최근 30일)
Christoph
Christoph 2013년 3월 24일
Hi at all,
I got a littel problem while using S-Function, written in C. At the beginning of the simualtion I compute some initial values. I want to pass out one of them on an output port during the mdlOutput Routine. For that reason I use the
ssGetSimStatus
function an compare the result with the following expression:
SIMSTATUS_INITIALIZING
As the result the output port is Zero for all time, which is actually not the expected one. Changing the expression to
SIMSTAUTS_RUNNING
leads to the correct behavior, even during the initializing. (I figured this out with the help of fprintf function).
Does anybody know a way to set an output port to a specified value once at the initializing?
To help you understand my current implementation and problem, I post a snippet of my code, placed in the mdlOutput function:
// Set Schedule Value of the Rolling Force
ssGetSimStatus(S, &SimStatus);
if (SimStatus == SIMSTATUS_INITIALIZING)
{ Output[0] = DWorkVec[0];
#ifdef __EchoMode__
fprintf(LogFile, "\tSet Schedule Value of the Rolling Force\n");
#endif
}
Thanks in advance, CN

채택된 답변

Kaustubha Govind
Kaustubha Govind 2013년 3월 27일
mdlOutputs is indeed executed only during model execution, so ssGetSimStatus should always return SIMSTATUS_RUNNING. I think the status is SIMSTATUS_INITIALIZING in mdlInitializeConditions, so you need to initialize your DWork vector there and then use the DWork vector value in mdlOutputs.

추가 답변 (1개)

Christoph
Christoph 2013년 3월 28일
Thanks for your support Kaustubha,
I initailized my DWorkVector the right way in the mdlInitializeConditions function. I only want to reuse this vector to keep the number of DWork vectors snall. But if there is no other way I have to use another DWork vector or a vector with more dimensions.

카테고리

Help CenterFile Exchange에서 Block and Blockset Authoring에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by