% Sample data
x = linspace(0, 2*pi, 100);
y1 = sin(x);
y2 = cos(x);
% Create the plot
figure;
plot(x, y1, 'b', 'LineWidth', 1.5);
hold on;
plot(x, y2, 'r--', 'LineWidth', 1.5);
hold off;
% Add legend
legend({'$\sin(x)$', '$\cos(x)$'}, 'Interpreter', 'latex', 'Location', 'best');
% Add axes labels
xlabel('$x$ (radians)', 'Interpreter', 'latex');
ylabel('Function value', 'Interpreter', 'latex');
% Set LaTeX style for axes ticks
xticks([0 pi/2 pi 3*pi/2 2*pi]);
xticklabels({'$0$', '$\frac{\pi}{2}$', '$\pi$', '$\frac{3\pi}{2}$', '$2\pi$'});
yticks([-1 -0.5 0 0.5 1]);
yticklabels({'$-1$', '$-0.5$', '$0$', '$0.5$', '$1$'});
% Set title with LaTeX
title('Plot of $\sin(x)$ and $\cos(x)$', 'Interpreter', 'latex');
% Set grid
grid on;
If you run this script, MATLAB will generate a plot with sinusoidal wave functions where all text elements are rendered using LaTeX formatting. Ensure that your MATLAB environment supports LaTeX interpretation, which is available in versions that support the 'Interpreter' property.