最近在短视频上老是刷到用matlab绘制的动态心形图,然后就跑到评论区留言求一份代码,没能收到回复,于是决定自己动手搞一下。
在绘图的过程中,我参考了下面的matlab代码。
% 该代码来自参考文章,文末已给出链接
clc;clear all;
a=10;
x=-2:0.01:2;
figure(1);
set(gcf,'position',[0,0,800,600],'color','w');
for i=1:100
str_title = strcat('\color{red}a=',num2str(a));
y = abs(x).^(2/3)+(0.9*sqrt((3.3-x.^2))).*sin(a*pi*x);
a=i/10;
figure(i);
set(gcf,'position',[0,0,800,600],'color','w');
p1 = plot(x,y,'r','LineWidth',3);
hold on;
title('\color{red}f(x)=x^2^/^3+e/3*(π-x^2)^1^/^2*sin(a*π*x)','fontsize',15);
text(-0.2,2.3,str_title,'FontName','Times New Roman','FontSize',20);
xlim([-2 2]);
ylim([-1.5 2.5]);
close(figure(i));
end
最终的结果如下 GIF 图所示!
上面动态心形图的代码:点此下载
本文参考文章:
Matlab绘制动态心形图