inputdlg to call a function on click ok

1 view (last 30 days)
kyin gab
kyin gab on 24 Nov 2012
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.

Answers (3)

Walter Roberson
Walter Roberson on 24 Nov 2012
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.

Matt Fig
Matt Fig on 24 Nov 2012
Edited: Matt Fig on 24 Nov 2012
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.

kyin gab
kyin gab on 25 Nov 2012
Thank you Math and Walter. I am new to MathLab, I did not really get what you guys were saying.
I just figured out that when I clicked ok the inputdlg returns the typed input back to the function that called. So I can continued form there.
I have more questions, and I just posted one with the title 'plotting dtmf frequencies'.
Thank you guys.

Categories

Find more on Startup and Shutdown 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!