How do I use "inputdlg" box as a prompt to get numbers for multiple variables?
18 views (last 30 days)
Show older comments
Currently, I know that if you put these commands in to an m file:
prompt = {'Enter former year','Enter former measurement','Enter new year','Enter distance from center'};
dlg_title = 'Input for fluke measurement';
yf = inputdlg(prompt,dlg_title)
I will get multiple numbers for the same variable, "yf". What I would like to do is use a dialog box in order to get numbers for multiple variables. So 'Enter former year' would ask for a number corresponding to the variable "yf" and 'Enter former measurement','Enter new year', and 'Enter distance from center' would ask for numbers corresponding to the variables "f", "yn", and "d" respectively. Is there a way to make a dialog box that does this?
Thanks for your help.
0 Comments
Answers (1)
Walter Roberson
on 17 Jan 2012
In the code you have above, the output yf will not exactly be "multiple numbers for the same variable": it will be a cell array of strings with one string per prompt that you used. You can extract the individual entries as you want.
If you really want them split in to variables, then:
temp = inputdlg(prompt,dlg_title);
[yf, f, yn, d] = temp{:};
Note: that syntax will not work on sufficiently old versions of MATLAB; the older syntax is
[yf, f, yn, d] = deal(temp{:});
2 Comments
Walter Roberson
on 19 Jan 2012
As I replied in your Question on this subject, http://www.mathworks.com/matlabcentral/answers/26548-how-do-i-ask-for-a-number-instead-of-an-array
No, inputdlg() always returns a cell array of strings. If you want to interpret them as numbers you have to convert them to numbers, such as with str2double()
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!