Azzera filtri
Azzera filtri

Numerical Input in Pop-up box

17 visualizzazioni (ultimi 30 giorni)
Elyse
Elyse il 26 Giu 2024 alle 12:00
Commentato: Star Strider il 26 Giu 2024 alle 13:25
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!

Risposta accettata

Star Strider
Star Strider il 26 Giu 2024 alle 12:39
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 Commenti
Elyse
Elyse il 26 Giu 2024 alle 12:44
This worked, thank you!
Star Strider
Star Strider il 26 Giu 2024 alle 13:25
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by