Assigning Dynamic Variables in Simulink
18 ビュー (過去 30 日間)
古いコメントを表示
How do I create a variable/ output a variable from a function using user defined matlab function block in simulink. The code of which is given below:
function y = fcn()
y = input('enter the variable value: ');
end
Using this code for the function gives an error in SIMULINK. I want Simlink to ask me for the value to be entered once I start the simulation.
Assume the there are only two blocks, i.e. User-defined function block and display block in simulink workspace.
2 件のコメント
Fangjun Jiang
2020 年 8 月 10 日
This is unrealistic. Keep in mind that the MATLAB Function block is executed in every simulation step, like every 1ms. Do you want to enter the value 1000 times for 1 second of simulation? What is your real need?
回答 (1 件)
Fangjun Jiang
2020 年 8 月 10 日
Put the code in Model Properties, Callbacks, InitFcn. It will be executed every time the simulation is run.
MyData=input()
MyData is a variable used by the Simulink model.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Simulink Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!