Modify generated LaTeX by setting symbolic preferences using
the sympref function.
Generate the LaTeX form of the expression π with the default symbolic preference.
sympref('default');
chr = latex(sym(pi))
chr =
'\pi '
Set the 'FloatingPointOutput' preference to
true to return symbolic output in floating-point
format. Generate the LaTeX form of π in
floating-point format.
Now change the output order of a symbolic polynomial. Create a symbolic
polynomial and set 'PolynomialDisplayStyle' preference to
'ascend'. Generate LaTeX form of the polynomial
sorted in ascending
order.
The preferences you set using sympref persist through
your current and future MATLAB® sessions. Restore the default values by specifying the
'default' option.
For and from to , plot the 3-D surface . Store the axes handle in a by using gca. Display the axes box by using a.Box and set the tick label interpreter to latex.
Create the x-axis ticks by spanning the x-axis limits at intervals of pi/2. Convert the axis limits to precise multiples of pi/2 using round and get the symbolic tick values in S. Display the ticks by setting the XTick property of a to S. Create the LaTeX labels for the x-axis by using arrayfun to apply latex to S and then concatenating $. Display the labels by assigning them to the XTickLabel property of a.
Repeat these steps for the y-axis. Set the x- and y-axes labels and the title using the latex interpreter.
syms xy
f = y.*sin(x)-x.*cos(y);
fsurf(f,[-2*pi 2*pi])
a = gca;
a.TickLabelInterpreter = 'latex';
a.Box = 'on';
a.BoxStyle = 'full';
S = sym(a.XLim(1):pi/2:a.XLim(2));
S = sym(round(vpa(S/pi*2))*pi/2);
a.XTick = double(S);
a.XTickLabel = strcat('$',arrayfun(@latex, S, 'UniformOutput', false),'$');
S = sym(a.YLim(1):pi/2:a.YLim(2));
S = sym(round(vpa(S/pi*2))*pi/2);
a.YTick = double(S);
a.YTickLabel = strcat('$',arrayfun(@latex, S, 'UniformOutput', false),'$');
xlabel('x','Interpreter','latex');
ylabel('y','Interpreter','latex');
zlabel('z','Interpreter','latex');
title(['$' latex(f) '$ for $x$ and $y$ in $[-2\pi,2\pi]$'],'Interpreter','latex')
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.