Numerical Input in Pop-up box

4 views (last 30 days)
Elyse
Elyse on 26 Jun 2024
Commented: Star Strider on 26 Jun 2024
Hi, I have a code that asks for inputs of numbers from the user. Currently it asks for inputs in the command window, but I would like it to ask in a pop-up box. When I use the inputdlg command it won't accept the values as numbers for later use, so I was wondering if there is a different way to ask the user for numbers in a menu so that it will know they are numbers.
This is the code that currently works for the command window:
askstartinch="What inch did you start from?\n";
start_inch=input(askstartinch);
askendinch="What inch did you end at?\n";
end_inch=input(askendinch);
asktrial="What trial number is this?\n";
trial=input(asktrial);
This is the code that I tried with the popup boxes, but it won't accept the values as numbers for later use in the code:
start_inch=inputdlg("What inch did you start from?");
end_inch=inputdlg("What inch did you end at?");
trial=inputdlg("What trial number is this?");
I would perfer the menu to have all 3 questions in popup box, but either way works I just can't seem to get it work. Thanks!

Accepted Answer

Star Strider
Star Strider on 26 Jun 2024
Try something like this —
trial_info = inputdlg(["What inch did you start from?","What inch did you end at?","What trial number is this?"], "Trial Info:", [1 50]);
start = str2double(trial_info{1})
finish = str2double(trial_info{2})
trial_nr = str2double(trial_info{3})
Make appropriate changes to get the result you want.
.
  2 Comments
Elyse
Elyse on 26 Jun 2024
This worked, thank you!
Star Strider
Star Strider on 26 Jun 2024
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!