putting a subscript into a string, displaying the command window

145 views (last 30 days)
I need to know how to properly put a character into subscript within a string and to display with the subscript. input: ? output: Look at the picture
Might as well include superscript as well. I care more about being able to display the subscript. Do not include anything including a graph. This is not going to be displayed in a graph. This is going to be displayed in the command window.

Answers (2)

Walter Roberson
Walter Roberson on 18 Nov 2015
See the file exchange contribution cprintf to see how you can use html on things you write to fid 2. Something like
fprintf(2,G<sub>5>
  4 Comments
Marco
Marco on 18 Nov 2015
input: fprintf(2,G<sub>5) output: Undefined function or variable 'sub'.
Guillaume
Guillaume on 18 Nov 2015
You obviously have to pass a string to fprintf, and if the <sub> tag worked, you would also have to close it. So the syntax would have been
fprintf('G<sub>5</sub>');
However, see my answer. You can't do what you want.

Sign in to comment.


Guillaume
Guillaume on 18 Nov 2015
It is not possible to display subscripts or superscripts in the command window. The java text control that matlab uses does not support formatting with only a few exceptions. The only formatting supported is underline, bold, and changing the text colour. All of these are done using undocumented features of matlab (so, may break in a future version of matlab).
underline is achieved using a html hyperlink tag, bold is achieved using the <strong> html tag. You can't have both at once. See cprintf documentation or Yair's (the author of cprintf) blog on the subject.
If matlab supported subscript through html tag the syntax would have been:
fprintf('G<sub>5</sub>');
You obviously have to give a string to fprintf, and you have to close the html tag.
  1 Comment
Marco
Marco on 18 Nov 2015
Thanks. I've been working on a chemical equation solver and this was supposed to be the last step, I've finished everything else. If no better answer exists yours will be the answer. Mark in 6 hours.

Sign in to comment.

Categories

Find more on Programming 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!