This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Including Symbols in Plots and User Interfaces

This example shows how to create mathematical symbols and special characters for plots and user interfaces using Unicode characters.

Create Unicode Characters

Create Unicode characters using the char function with an integer argument. Integer values for Unicode characters can be found at

quart = char(188);     % 1/4 symbol
half = char(189);      % 1/2 symbol
quart3 = char(190);    % 3/4 aymbol
piStr = char(960);     % Greek letter pi
phi = char(966);       % Greek letter phi
psi = char(968);       % Greek letter psi
omega = char(969);     % Greek letter omega
arrow = char(8594);    % right arrow

Plot a Sin Curve

t  = 0:.1:2*pi;
y = sin(.75*pi*t + .5*pi);

figure('InvertHardcopy', 'off')
xlim([0 2*pi])

Add Characters to Axes and Tick Labels

You can include Unicode characters in axes labels and in tick labels.

xlabel(['angle ' arrow])
ylabel(['sin(' omega 't + ' phi ')' arrow])

ax = gca;
ax.XTick = [0:.25:2]*pi;    % create tick marks at 1/4 multiples of pi
ax.XTickLabel = {0, [quart piStr], [half piStr], [quart3 piStr], piStr,... 
    ['1' quart piStr], ['1' half piStr], ['1' quart3 piStr], ['2' piStr]};

Add Characters to User Interfaces

Unicode characters also apply to user interface components. Set the String property of text, edit boxes, buttons and other uicontrols.

ax.Position(4) = 0.75;                    % make the axes shorter
pstr = ['Phase (' phi ' & '  psi ')'];    % create the string for a text box
textPhase = uicontrol('Position', [190 375 100 30], 'Style', 'text', 'FontSize', 10, 'String', pstr);
editPhase = uicontrol('Position', [300 380 80 30], 'Style', 'edit', 'String', '2.5');

More Unicode Characters

There are many different characters, mathematical symbols, currency symbols, and languages that can be represented using Unicode characters. For more information see:

skull = char(9760);
snowman = char(9731);

textSkull = uicontrol('Position', [20 380 30 40], 'Style', 'text', 'FontSize', 25, 'String', skull);
textSnowman = uicontrol('Position', [510 380 30 40], 'Style', 'text', 'FontSize', 25, 'String', snowman);

Was this topic helpful?