필터 지우기
필터 지우기

Assigning Dynamic Variables in Simulink

조회 수: 6 (최근 30일)
Sushanth Manchikatla
Sushanth Manchikatla 2020년 8월 10일
답변: Fangjun Jiang 2020년 8월 10일
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
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?
Sushanth Manchikatla
Sushanth Manchikatla 2020년 8월 10일
I need to create an interface where I can fix variable(s) by chosing from a prompt given by simulink/matlab. So how do I code this prompt? And this variable is fixed for all the simulations. I dont want to put the variable as a constant and change the value by opening the workspace everytime. Instead I need a seperate code which allows me to change the value for every execution.

댓글을 달려면 로그인하십시오.

답변 (1개)

Fangjun Jiang
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.

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by