create a simple small text box asking for user input of variables in matlab

To create a simple small text box in MATLAB, you can use the inputdlg function. This function displays a modal dialog box that prompts the user for input. Here's an example of how you can use it to ask for user input:

main.m
% Prompt the user to enter input variables
prompt = {'Enter variable 1:', 'Enter variable 2:', 'Enter variable 3:'};
dlgtitle = 'Enter Variables';
dims = [1, 40];
defaultInput = {'', '', ''};
userInput = inputdlg(prompt, dlgtitle, dims, defaultInput);

% Access the user input
variable1 = str2double(userInput{1});
variable2 = str2double(userInput{2});
variable3 = str2double(userInput{3});

% Display the entered variables
disp(['Variable 1: ' num2str(variable1)]);
disp(['Variable 2: ' num2str(variable2)]);
disp(['Variable 3: ' num2str(variable3)]);
553 chars
17 lines

In this example, the inputdlg function prompts the user to enter three variables. The user's input is stored in the userInput variable, which is a cell array. We then use str2double to convert the input from strings to numbers, and assign them to the respective variables. Finally, we display the entered variables using the disp function.

Note that in the defaultInput variable, you can provide default values for the input boxes.

related categories

gistlibby LogSnag