How to Make Word Inputs in MATLAB
Matrix Laboratory (MATLAB) is both a powerful mathematical tool and a high-level programming language, allowing you to create routines that interact with a user to perform a computation task. Use the "input" function to solicit text input from the user within the Command Window. Use "inputdlg" to display a pop-up box prompting the user to input one or more words.
Instructions
-
Command Window
-
1
Type the following line of code to prompt the user to enter a word or string in the Command Window, storing the result in a variable called "userinput:"
userinput = input('Type a word:','s');
-
2
Use the special "\n" character in the prompt string to make a multi-line prompt:
userinput = input('Type a word,\nthen press Enter:\n','s');
-
-
3
Use "\\" to put a backslash in the prompt string:
userinput = input('Type your name\\pseudonym:\n','s');
Pop-up Box
-
4
Type the following command to display a box prompting the user to input a word:
userinput = inputdlg('Type a word here:');
-
5
Add a second argument to title the box:
userinput = inputdlg('Type a word here:','Input Request');
-
6
Prompt for multiple inputs in a single box with a cell array:
userinput = inputdlg({'Name','Age','Height'},'Input Request');
If you use this format, "userinput" will contain a cell array of the user's inputs after the box is completed.
-
7
Specify the number of lines in the input field with a third argument:
userinput = inputdlg('Type a word here:','Input Request',3);
You can specify different text field sizes for different prompts if you use a vector or matrix for this argument. Type "help inputdlg" for details.
-
8
Use default values (the fourth argument) for the input fields to prompt the user in the fields themselves:
userinput = inputdlg({'','',''},'Input Request',1,{'Name','Age','Height'});
-
1