How to communicate with Simulink from within a function?

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 日

0 投票

Please see my answer to a similar question here.

1 件のコメント

Daniel
Daniel 2013 年 5 月 1 日
Very good, thank you for the help. :-)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEvent Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by