How to display numerical data as subscript text in the UIAxes in App Designer when the data has multiple digits?

5 views (last 30 days)
Hi,
So I'm trying to create shapes in App Designer and insert labels within each shape. I'm using a for-loop to do this. Each index of the for-loop is referenced in creating part of the label for the shapes in the UIAxes. The sprintf function is used to convert the data into a string to display it at some coordinates. Here's an example:
text(app.UIAxes,50, 50, sprintf('%s_%d_%d', 'd^q',1,5), 'Fontsize',40)
axis([0 100 0 100])
The issue I've encountered is when this code is used, it provides the label where (d^q)_5. When I run this similar code in a Matlab script file, it works fine providing me with (d^q)_15.
Similar code:
text(50, 50, sprintf('%s_%d_%d', 'd^q',1,5), 'Fontsize',40)
axis([0 100 0 100])
It shows the number "15" as the subscript of "d" to the superscript of "q". I have no idea how to fix this. Please help me or tell me if it is even possible.

Accepted Answer

Kai Domhardt
Kai Domhardt on 7 Feb 2018
You can use curley brackets to specify where the sup-/superscript starts and ends. See Text, under Interpreter.
text(app.UIAxes,0, 0.5, sprintf('%s_{%d_%d}}', 'd^{q',1,5), 'Fontsize',40)
would be 1 as subscript of q and 5 as subscript of 5.
If you just want 1 and 5 as subscript of d^q, this would do the trick:
text(app.UIAxes,0, 0.5, sprintf('%s_{%d%d}', 'd^{q}',1,5), 'Fontsize',40)

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!