How to communicate with Simulink from within a function?

12 次查看(过去 30 天)
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