Space in a text is taken as line break in UIcontrol

3 次查看(过去 30 天)
I have a long string variable like this.
tex = "Date=09-Jul-2024 Delta_E=-3.3317 Delta_U=300-320V Sigma=0.094335 MaxAbs=0.00056882 MeanAbs=-0.079426 MaxRel=0.012132 eanRel=-0.9771 AllowedDeviation=0.05-0.1"
I am trying to represent this in a fig as UIcontrol using this line of code
txt_title = uicontrol('Style', 'text', 'String',tex,'FontSize',10,'Position', [100 200 180 150]);
But space in the string variable is read as line break. Why is that, i tried removing linebreak using strtrim, erase(tex,char(10)). But nothing is working.
I need this in one line and not like this. What is the error? Thank you.
  3 个评论
Romain
Romain 2024-7-9
编辑:Romain 2024-7-9
Hi,
The problem comes from your 'Position' vector, precisely from the width argument (180). The width is too low and matlab display string tex as a column to fit the data in the given width.
One way to go around is to increase 'width', another could be using uigridlayout in 'fit' mode.

请先登录,再进行评论。

回答(1 个)

Sourabh
Sourabh 2024-7-9
This behaviour could likely be due to the width of the control not being wide enough to display the entire string on one line.
figure;
tex = "Date=09-Jul-2024 Delta_E=-3.3317 Delta_U=300-320V Sigma=0.094335 MaxAbs=0.00056882 MeanAbs=-0.079426 MaxRel=0.012132 eanRel=-0.9771 AllowedDeviation=0.05-0.1";
% Reducing font size and increasing width of the control
txt_title = uicontrol('Style', 'text', 'String',tex,'FontSize', 8, 'Position', [100 200 500 150]);
As you can see, by changing the width of the control to 500, it is possible to accomodate more text in each line. You can even try using different fonts and altering parameters like 'Font Size'.

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by