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

8 ビュー (過去 30 日間)
Tuan
Tuan 2022 年 8 月 5 日
回答済み: Shlok 2025 年 4 月 29 日
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!

回答 (1 件)

Shlok
Shlok 2025 年 4 月 29 日
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:

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by