Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use text Control in MATLAB_GUI

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use the text control in MATLAB_GUI, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Text control

This text control, used to display static text, is generally used to prompt, can be used to prompt for status, file name, path, etc., I generally call it a label. So basically we only need to know some of the following properties, and the callback function of the text control is generally not used:

Style: controls the type of UI control, which needs to be written as text

Parent: the parent container that controls the UI control. In popular terms, it tells the UI control who should be placed on it (direct relationship). At present, without talking about the layout, it can only be placed directly on the figure. When you talk about the layout, these controls are placed in the layout. Although the layout is still placed directly or indirectly in the figure. In order to indicate where the button is placed, this Parent property must be written (although sometimes it is OK not to write it).

String: the string displayed on the text control.

BackgroundColor: sets the background color of the text control, which can be the letters that represent the color, such as: 'Kwon,' raster, 'Gmail,' b', etc., or it can be a vector of 1: 3, each element between 0-1 represents the value of rjournal gjournal b.

The color of the string (String) on the ForegroundColor:text control

The size of the character (String) on the FontSize:text control

Font of the character (String) on the FontName:text control

Visible: controls whether the text control is visible, which is visible by default

Units: the unit that controls the value of the Position of the text control, usually in pixels: 'pixels', if you want to set the unit, the unit must be set before the Position.

Position: controls the position of the text control in the window. If you take the computer screen as the coordinate plane, then the lower left corner of the computer screen is the origin, and the value of position is: [X, y, w, h]:

Figure 1

The text control is created in the same way as the button in the previous installment, except that the value of the style property is changed to text.

As to how to set the property value, how to get the property value of the control, and how to get the property value and which property can be set, these have been repeated in the first two installments, so I won't repeat them here and in the future push!

Examples

The creation of two text controls are marked as text1,text2, the sizes of which are both 120 and 64, respectively. The string is text1,text2.

Create a button 1, the color is green, the size is 64cm 64, the position is random, the String on the button is to set the color of the text1 control to green, click the button 1 to set the color of text1 to green.

Create a button 2, the color is red, the size is 64cm 64, the position is random, the String on the button is to set the text2 control color to red, click button 2 to set the text2 color to red.

It seems that at the beginning of version 16, you can write multiple functions in the same m file. If it is version 14, you need to write the callback function into a separate file!

With regard to the writing of the callback function, as mentioned in the previous issue, this issue is combined with the callback function of the button in the previous issue.

Example code function main ()

Close all

Create main window

H_fig = figure ('Name',' MATLAB_GUI_ tutorial (3) text',...

'MenuBar', 'none',...

'ToolBar',' none')

% create button

Btn1 = uicontrol ('Style',' pushbutton',...

'Parent', h_fig,...

'String',' sets the color of the text1 control to green.

'Units', 'pixels',...

'Position', [50 50 64 64],

'Callback', {@ callback_btn1, h_fig})

Setappdata (h_fig, 'btn1', btn1);% saves btn1 to appdata for use in other callback functions

Btn2 = uicontrol ('Style',' pushbutton',...

'Parent', h_fig,...

'String',' sets the color of the text2 control to green.

'Units', 'pixels',...

'Position', [50 200 64 64],...

'Callback', {@ callback_btn2, h_fig})

Setappdata (h_fig, 'btn2', btn2);% saves btn2 to appdata for use in other callback functions

Text1 = uicontrol ('Style',' text',...

'Parent', h_fig,...

'String', 'text1',...

'Units', 'pixels',...

'Position', [200 200 120 64])

Setappdata (h_fig, 'text1', text1);% saves text1 to appdata for use in other callback functions

Text2 = uicontrol ('Style',' text',...

'Parent', h_fig,...

'String', 'text2',...

'Units', 'pixels',...

'Position', [100 300 120 64])

Setappdata (h_fig, 'text2', text2);% saves text2 to appdata for use in other callback functions

End

I can't use the callback function of%% button 1, obj or event, so use ~ instead

Function callback_btn1 (~, h_fig)

% get text1

Text1 = getappdata (h_fig, 'text1')

Click button 1 to set the color of text1 to green.

Text1.BackgroundColor ='r'

End

I can't use the callback function of%% button 2, obj or event, so use ~ instead

Function callback_btn2 (~, h_fig)

% get text2

Text2 = getappdata (h_fig, 'text2')

Set the color of text2 to red when you click button 2.

Text2.BackgroundColor ='r'

End

Example result result

Thank you for reading this article carefully. I hope the article "how to use text controls in MATLAB_GUI" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report