using inputdlg function in user defined function
3 views (last 30 days)
Show older comments
Hello
I would like to write this code in matlab function in simulink file
function y = fc()
y=0;
coder.extrinsic('inputdlg');
prompt = {'Enter 1 for Yes 0 for NO'};
dlgtitle = 'Input';
dims = [1 35];
answer = inputdlg(prompt,dlgtitle,dims)
end
when I run the simulation ,the diagloge box apear several time during simulation.
I would like to apear the box only one and keep on the simulation run
could help me to do this?
Another question
I need to add switch case like this
function y = SW_case()
y=0;
coder.extrinsic('inputdlg');
prompt = {'Enter 1 for Yes 0 for NO'};
dlgtitle = 'Input';
dims = [1 35];
answer = inputdlg(prompt,dlgtitle,dims);
switch answer{1}
case 1
y=100
case 0
y=10
end
when I run the simulation
there is an error ocure
Cell contents reference from a non-cell array object.
Function 'MATLAB Function1' (#23.178.187), line 8, column 8:
"answer{1}"
thanks alot in advanced
2 Comments
Answers (2)
Walter Roberson
on 6 Aug 2022
Edited: Walter Roberson
on 7 Aug 2022
"I would like to apear the box only one and keep on the simulation run"
That is not possible with inputdlg()
Steven Lord
on 8 Aug 2022
Since you're doing this in a MATLAB Function block, rather than bringing up a dialog each time I'd consider using a Constant block or perhaps one of the Customizable Blocks to define an input to that block.
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!