How to communicate with Simulink from within a function?

조회 수: 12 (최근 30일)
Daniel
Daniel 2013년 5월 1일
Hello everybody,
I do have communication problems with Simulink from within a function. I am used to use the sim()-command in m-files which are not declared as functions. Here I am able to define all constants inside my m-file, which are stored in the base workspace, and Simulink will use them (happily). But - and thats my problem - if I change the m-file to a function, calling this function from the 'Command Window', it isn't able to use these constants. This is the error message I get:
Error using runsim (line 43) Error due to multiple causes.
Caused by: Error using runsim (line 43) Error evaluating parameter 'Gain' in 'ball_beam/ball and beam model/Gain' Error using runsim (line 43) Undefined function or variable 'g'. Error using runsim (line 43) Error evaluating parameter 'Gain' in 'ball_beam/open-loop controller/Gain' Error using runsim (line 43) Undefined function or variable 'g'. Error using runsim (line 43) Error evaluating parameter 'Gain' in 'ball_beam/state feedback controller/K' Error using runsim (line 43) Undefined function or variable 'K'.
Well, next step is to ask the mathworks help :-): http://www.mathworks.de/de/help/simulink/ug/using-the-sim-command.html
Here it says: SimOut = sim('model', Parameters) Unfortunately, 'Parameters' seem to be simulation parameters like 'RapidAcceleratorParameterSets' which I found here: http://www.mathworks.de/de/help/simulink/slref/sim.html
So, how to solve this problem? Thank you for your help.

채택된 답변

Kaustubha Govind
Kaustubha Govind 2013년 5월 1일
Please see my answer to a similar question here.

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by