matlab画动漫,求助matlab绘制动画命令

本人用了最麻烦的方法。将x设为一个两行cnt列的矩阵。每次迭代的时候计算第cnt列,每计算一次就将x矩阵增加一列。每次画图的时候都是画所有x矩阵的点。刚刚学习,不知道和前排大神的方法是否一样。

可是这么做x矩阵会越来越大,内存占用较大,并不是一个完美解决的方法。将code上传,供各位同好交流。

function fern_newver

%FERN  MATLAB implementation of the Fractal Fern

%   Michael Barnsley, Fractals Everywhere, Academic Press, 1993.

%   This version runs forever, or until stop is toggled.

%   See also: FINITEFERN.

%   Copyright 2013 Cleve Moler

%   Copyright 2013 The MathWorks, Inc.

shg

clf reset

set(gcf,'color','white','menubar','none', ...

'numbertitle','off','name','Fractal Fern')

x = [.5; .5];

h = plot(x(1,:),x(2,:),'.');

darkgreen = [0 2/3 0];

set(h,'markersize',1,'color',darkgreen,'erasemode','none');

axis([-3 3 0 10])

axis off

stop = uicontrol('style','toggle','string','stop', ...

'background','white');

drawnow

p  = [ .85  .92  .99  1.00];

A1 = [ .85  .04; -.04  .85];  b1 = [0; 1.6];

A2 = [ .20 -.26;  .23  .22];  b2 = [0; 1.6];

A3 = [-.15  .28;  .26  .24];  b3 = [0; .44];

A4 = [  0    0 ;   0   .16];

cnt = 1;

tic

while ~get(stop,'value')

r = rand;

if r < p(1)

x1 = A1*x(:,cnt) + b1;

elseif r < p(2)

x1 = A2*x(:,cnt) + b2;

elseif r < p(3)

x1 = A3*x(:,cnt) + b3;

else

x1 = A4*x(:,cnt);

end

x =[x,x1];

set(h,'xdata',x(1,:),'ydata',x(2,:));

drawnow

cnt = cnt + 1;

end

t = toc;

s = sprintf('%8.0f points in %6.3f seconds',cnt,t);

text(-1.5,-0.5,s,'fontweight','bold');

set(stop,'style','pushbutton','string','close','callback','close(gcf)')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值