0

I have created an uiTable in Matlab. Now I need to write column headers and some cell data, which contain greek letters and subscripts. In text objects or plots I would just enable the TeX interpreter - or it is even the default setting. This does not work in an uiTable. How would I do this here? Maybe pre-formatting the strings somehow?

If there would be a solution, the next question will be: I need this interpreter only in some cells (and column headers). Some other need to be printed as the strings are given. So basically, I would even need an individual TeX interpreter setting per cell. But I know this would be solvable by the correct string escaping...

Minimal example:

h = figure();
t=uitable(h);
set(t,'ColumnName',{'test_1';'\alpha'})

This looks like this. But it should be rather with an index "1" and an alpha character.

2 Answers2

0

You can use html and unicode char to do what you want in the column headers.

You could use the str2html FEX submission to create the html and you need to know the unicode char for the greek letters:

h = figure();
t=uitable(h);

str = str2html ( 'test', 'subscript', '1' );
set(t,'ColumnName',{str; char(945)})


Note: the html in this example is: <HTML>test<sub>1</sub></HTML>

This produces:

enter image description here

You can use the same theory to display in the individual cells:

h = figure();
t=uitable(h);

str = str2html ( 'test', 'subscript', '1' );
Data{2,2} = str;
Data{3,3} = str2html ( 'test', 'superscript', '2' );
Data{4,1} = str2html ( '90', 'superscript', char(176) );
set(t,'ColumnName',{str; char(945); char(946)},'Data', Data)

enter image description here

matlabgui
  • 5,642
  • 1
  • 12
  • 15
  • This is the perfect solution! Thank you! Just a small downside: the char() method does not work - it outputs the correct string in the Matlab command window, but not in the table. Here I see only spaces where the greek letters should be. But of course I could set Greek letters with HTML too. Didn't know about this neat feature of HTML interpretation. – monoceros84 Jan 13 '17 at 10:55
0

Thanks for the str2html trick! For simple unicode symbols I came to this solution:

strUnicodeChar = char(hex2dec( '21C4' )); 

That will give symbol of ⇄.

Unicodes can be found here https://unicode-table.com/de/#21C4

Timo
  • 1
  • 2