How to Convert Text to Uppercase and Special Formats in MATLAB?

57 views (last 30 days)
Hey everyone,
I’m working on a project where I need to dynamically convert text to different formats in MATLAB. Specifically, I'm dealing with:
  • Converting text to uppercase and lowercase.
  • Applying styles like bold or italic text for use in GUI components.
  • Removing extra spaces and line breaks from strings to clean up user inputs.
  • Reversing text or transforming it into special formats for visualization purposes.
I’ve been able to handle basic string manipulations using upper(), lower(), and regexprep() functions, but I’m running into issues when it comes to more complex transformations (like bubble text, upside-down text, or generating superscript).
Is there a streamlined way in MATLAB to handle such cases, or would it require writing custom functions? I came across a tool that offers various text transformations (like uppercase, lowercase, bubble text, and even specialized formats) that made me wonder if there's a way to integrate similar functionalities into MATLAB. You can check out some examples here.
Has anyone tried implementing advanced text formatting in MATLAB, or is there a toolbox that supports this?
Thanks in advance for any suggestions or guidance!
  4 Comments
Stephen23
Stephen23 on 12 Nov 2024 at 16:43
Edited: Stephen23 on 12 Nov 2024 at 20:48
"Bubble text" seem to be simply the Enclosed Alphanumeric characters defined by Unicode:
sprintf('\x24bd\x24d4\x24db\x24db\x24de \x24cc\x24de\x24e1\x24db\x24d3')
ans = 'Ⓗⓔⓛⓛⓞ Ⓦⓞⓡⓛⓓ'
Note that Unicode also provides some superscript and subscript characters (unfortunately spread over many blocks):
sprintf('Hello \x1d42\x1d52\x02b3\x02e1\x1d48')
ans = 'Hello ᵂᵒʳˡᵈ'
To use them just put all of those character codes in a lookup table. That is all those websites do.
For a project like this you need to investigate what Unicode defines.
Walter Roberson
Walter Roberson on 12 Nov 2024 at 18:58
Note: using advanced Unicode characters such as these, is not compatible with using 'LaTex' interpreter. It is compatible with using interpreter 'none' or 'TeX'

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 11 Nov 2024 at 20:24
Edited: Walter Roberson on 11 Nov 2024 at 20:26
A non-trivial problem that you will run into, is that styles and "special formats" cannot be directly encoded into text.
You can uitextarea() or uicontrol() style 'text' or text() with FontWeight 'bold', or with FontAngle 'italic'. However, this will apply to the entire text area, not just to selected characters.
If you use text() then there is the additional option of 'Interpreter', 'text' or 'Iatex'. These permit you to submit encoded strings that will be interpreted. A list of supported TeX encodings is at https://www.mathworks.com/help/matlab/ref/text.html#f68-481090_sep_shared-Interpreter
If you use uitable() with a uifigure() then you can add a uistyle component. One of the supported uistyle components is 'Interpreter', 'html' https://www.mathworks.com/help/matlab/ref/uistyle.html#mw_5d6181cc-0262-479d-ba56-003cdd71e6c8 or 'Interpreter', 'latex' https://www.mathworks.com/help/matlab/ref/uistyle.html#mw_bc609e92-e251-4225-9da5-4392eb3581ac
  2 Comments
Walter Roberson
Walter Roberson on 11 Nov 2024 at 21:40
upside-down text is most easily done by flipping the text end-for-end and then using text() with Rotation property... provided that all of the text is to be affected.
Superscript text is most easily done by using text() with TeX or LaTeX encoding, and using '^{' followed by the text followed by '}' such as
e^{\pi i}
Kishore
Kishore on 12 Nov 2024 at 6:30
Thank you for the suggestion. I will try it today...

Sign in to comment.

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!