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?

 채택된 답변

Image Analyst
Image Analyst 2011년 10월 17일

0 개 추천

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

Du Tran
Du Tran 2011년 10월 17일
thanks you, Image Analyst. I got it.
Daniel Liberman
Daniel Liberman 2020년 3월 18일
편집: Image Analyst 2020년 3월 18일
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.
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;

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2011년 10월 15일

0 개 추천

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.

댓글 수: 1

Du Tran
Du Tran 2011년 10월 17일
thanks Mr Roberson. If I use GUI to create editboxes and show elements into these boxes, what could I do?

댓글을 달려면 로그인하십시오.

kyaw zaw
kyaw zaw 2017년 12월 7일

0 개 추천

I want to show result data that is shown in simulink Display block in GUI edit box. How can i solve?

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2011년 10월 15일

댓글:

2020년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by