Clear Filters
Clear Filters

Space in a text is taken as line break in UIcontrol

32 views (last 30 days)
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 Comments
Romain
Romain on 9 Jul 2024 at 12:31
Edited: Romain on 9 Jul 2024 at 12:46
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.
Govind Sankar Madhavan Pillai Ramachandran Nair
Thank you. Yes that was the issue. I increased the width and it worked

Sign in to comment.

Answers (1)

Sourabh
Sourabh on 9 Jul 2024 at 12:55
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'.

Tags

Community Treasure Hunt

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

Start Hunting!