get input dialog for a time value (t) using in physic problem

7 Ansichten (letzte 30 Tage)
Tuan
Tuan am 5 Aug. 2022
Beantwortet: Shlok am 29 Apr. 2025
I have a physics excercise, which requires me to get input from user for each value to calculate the math problem. My question is how can I get a range value of double (integer etc...) throw a input dialog function , please help me with this!

Antworten (1)

Shlok
Shlok am 29 Apr. 2025
Hi Tuan,
As per my understanding, you want to prompt the user to input multiple values one at a time.
This can be achieved by using a loop with the "inputdlg" function to collect each value individually and store them in an array. The "inputdlg" function in MATLAB creates a pop-up dialog box that prompts the user to input text data. You can use it inside a loop to repeatedly ask for different values. Here is a sample code to achieve the same:
n = 5; % Number of time values
t = zeros(1, n); % Preallocate array for inputs
for i = 1:n
prompt = {sprintf('Enter time value #%d:', i)};
dlg_title = 'Input Time';
dims = [1 35];
definput = {'0'}; % Default input
answer = inputdlg(prompt, dlg_title, dims, definput);
if isempty(answer) % If user clicks on cancel button
error('User cancelled the input.');
end
t(i) = str2double(answer{1});
if isnan(t(i))
error('Invalid input. Please enter a numeric value.');
end
end
disp('Time values entered:');
disp(t);
To know more about "inputdlg" function, refer to the following MathWorks Documentation link:

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by