MATLAB Answers

How do I enter and evaluate multiple lines in a GUI edit box that I created in MATLAB?

65 views (last 30 days)
I am trying to create a GUI with an edit box. In the edit box, I would like to be able to enter several lines and then evaluate the lines that I entered. Every time I press enter, the callback is evaluated without letting me add more lines.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Jul 2020
Edited: MathWorks Support Team on 10 Jul 2020
You can set a multi-line edit box by modifying the "max" uicontrol property of the edit box. If
MAX - MIN > 1
then editable text boxes accept multiline input. If
MAX - MIN <= 1
then editable text boxes accept only single line input.
You can change this parameter in two ways:
From GUIDE:
1) Double click on the edit box in question to bring up the Property Inspector.
2) Change the value of MAX to the desired number.
From the command line (or in a script):
1) Use the SET command with the following syntax:
set(h_edit,'Max',N);
where h_edit is the handle for the edit box and N is the desired number for MAX.
For more information on UICONTROL properties please take a look at the following documentation:
Please Note: The way the callback is executed is different for single and multiple lines. For more information on this, please see CALLBACK property from the above link.
You can evaluate the lines of text entered into the edit box in two ways. You can use the EVALMCW command (Evaluate Matlab Command Window) as follows:
 
evalmcw(h_edit)
where "h_edit" is the handle to the edit text box. The second method is to write your own FOR loop as follows:
 
s = get(h_edit,'string'); %h_edit is the handle to the edit box
[row, column] = size(s);
for i = 1:row
eval(s{i,:}) %evaluate each line as in MATLAB command prompt
end

  0 Comments

Sign in to comment.

More Answers (0)


Translated by