在本示例中,将给出如何用matlab绘制示意图,添加图例,添加标题等等,以及在matlab中调用LaTeX字体的命令。
代码如下:
clear;clc;close all
% Initialize symbolic variables
syms x f df
% example
disp('An Example, Plot Function and Derivative')
f = sin(x^2)
df = diff(sym(f));
pretty(df)
xx = linspace(-5,5);
x = xx;
fx = eval(f);
dfx = eval(df);
plot(xx,fx,'r-','LineWidth',2)
hold on
plot(xx,dfx,':b','LineWidth',2)
grid on
set(gca,'FontSize',12);
set(gca,'LineWidth',2);
set(gca,'TickDir','out');
xlabel('x','FontSize',20);
ylabel('$f(x)$, $\frac{df(x)}{dx}$','FontSize',20,'Interpreter','latex')
title(['$' latex(f) '$ and Derivative $' latex(df) '$'] ,'FontSize',30,'Interpreter','latex')
legend(...
'$f(x)$',['$\frac{df(x)}{dx}$=$' latex(df) '$'],...
'FontSize',20,...
'Location','north',...
'Interpreter','latex'...
)
fn_plot=['SymbolicExample.png'];
print('-dpng',fn_plot);% save to a png file
fn_plot=['SymbolicExample.eps'];
print('-depsc2',fn_plot);% save to a color eps file

这篇博客介绍了如何使用MATLAB进行示意图的绘制,包括添加图例、标题等操作,并展示了调用LaTeX字体的示例,帮助读者掌握MATLAB的图形美化技巧。

9397

被折叠的 条评论
为什么被折叠?



