display a value in edit text in GUI
8 views (last 30 days)
Show older comments
I had an array with 3 elements, I want to display each of them in 3 edit text boxs. Please guide me how to do this?
0 Comments
Accepted Answer
Image Analyst
on 17 Oct 2011
If you're using GUIDE, then whenever you want to send something to an edit field, you need to use set:
string1 = sprintf('M(1) = %.3f', M(1));
set(handles.edit1, 'String', string1);
string2 = sprintf('M(2) = %.3f', M(2));
set(handles.edit2, 'String', string2);
string3 = sprintf('M(3) = %.3f', M(3));
set(handles.edit3, 'String', string3);
You need to make sure that you have "handles" available (in scope). It will be in a callback, but if it's just some other function that got called, then you should pass handles in via the input argument list.
3 Comments
Daniel Liberman
on 18 Mar 2020
Edited: Image Analyst
on 18 Mar 2020
Hi,
What if I have 3 vectors and I want to print all the vectors members one after another without deleting the previous ones? Also, I want to print all of them at the same edit text box.
Image Analyst
on 18 Mar 2020
string1 = sprintf('M(1) = %.3f', M(1));
string2 = sprintf('M(2) = %.3f', M(2));
string3 = sprintf('M(3) = %.3f', M(3));
% Put all together on different lines into one string.
string1 = sprintf('%s\n%s\n%s', string1, string2, string3)
handles.edit1.String = string1;
More Answers (2)
Walter Roberson
on 15 Oct 2011
eh1 = uicontrol('Style','edit','Position', POSITION1);
eh2 = uicontrol('Style','edit','Position', POSITION2);
eh3 = uicontrol('Style','edit','Position', POSITION3);
set(eh1, 'String', num2str(YourArray(1)));
set(eh2, 'String', num2str(YourArray(2)));
set(eh3, 'String', num2str(YourArray(3)));
Here, the POSITION1 etc would be 4-element vectors giving the position and size you want for that particular edit box. For example,
POSITION1=[1/3, 1/2, 1/4, 1/5];
This would mean that the bottom left corner of the uicontrol should be positioned 1/3 of the way from the left border of the figure, 1/2 of the way up from the bottom of the figure, and that the width of the control should be 1/4 of the figure (so the right edge would be 1/3+1/4) and the height of the control should be 1/5 of the figure (so the top edge would be 1/2+1/5.)
You may have noticed in the above that the coordinates were "normalized", expressed as fractions of the height or width. That can work well for positioning the bottom corner of the figure if you do not know exactly (to the pixel) how big the figure is, such as if you want to support the user resizing the figure. On the other hand, using fractions for the width and height is usually a recipe for a mess.
There are other ways of specifying what the position coordinates designate, which you can invoke by using a 'Units' parameter before the Position, such as
uicontrol('Style','edit','Units', 'points', 'Position', [76,189,157,24])
That would start 76 points across, 189 points up, and would be 157 points wide and 24 points high. 1 point is 1/72 of an inch.
kyaw zaw
on 7 Dec 2017
I want to show result data that is shown in simulink Display block in GUI edit box. How can i solve?
0 Comments
See Also
Categories
Find more on String in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!