using inputdlg function in user defined function

2 views (last 30 days)
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
mona ali
mona ali on 8 Aug 2022
Edited: Walter Roberson on 8 Aug 2022
Thanks alot dpb for response
I upload the model (it is a simple example for what I need )
I used the questdlg function and switch case
still error
An error occurred while running the simulation and the simulation was terminated
Caused by:
Undefined function 'check_switch_expression' for input arguments of type 'char'.
if I used num2str function
function y = SW_case1()
coder.extrinsic('questdlg')
coder.extrinsic('str2num')
answer = questdlg('Would you like a dessert?', ...
'Dessert Menu', ...
'1','2','0','0');
a=str2num(answer)
switch a
case 1
y=1.75
case 2
y=3
case 'No thank you'
y=3.5
otherwise
y=3.5+(0.5)
end
still error
An error occurred while running the simulation and the simulation was terminated
Caused by:
Undefined function 'check_switch_expression' for input arguments of type 'double'.

Sign in to comment.

Answers (2)

Walter Roberson
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()
  3 Comments
mona ali
mona ali on 9 Aug 2022
Thank you so much Walter Robertson
yes still opening the message every step time
is there any way to do that ? in simulation
I would like to appear a message at if condition is activate
and according to may choose the certain task is occurred

Sign in to comment.


Steven Lord
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.
  1 Comment
mona ali
mona ali on 8 Aug 2022
Thank you sir for helping me
This code is a part of my code I need to appear The message box after if condition activate and according to the choose of the message box ,the certain task is occurred
I don’t need a constant block or any input to a user defined function
Can I do it?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by