inputdlg to call a function on click ok
显示 更早的评论
Hello,
I would like the expert in the house to help me with this.
I have an inputdlg. I want when the ok button is pressed, it should automatically call another function which is stored as an m file. Also, it should pass its value answer as inout to that called function.
I would help here and some examples.
Thank you.
回答(3 个)
Walter Roberson
2012-11-24
0 个投票
You would need to modify the code for inputdlg() to do that, or else create your own inputdlg.m function that was earlier on the path and did what you want.
There are may ways to do this:
P = {'Enter a number on [1,5]: '};
N = 'Input for ONES function.';
M = 1;
D = {'3'};
F = ones(str2double(inputdlg(P,N,M,D))) % Pass to ONES.
Note that it may be (read: is) a good idea to have some error checking instead of just passing the INPUTDLG call to STR2DOUBLE. For example, if the user enters pi, you will get an error... You could wrap all this code plus the error checking into a new function called, myinputdlg.m then use it as needed.
类别
在 帮助中心 和 File Exchange 中查找有关 Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!