生成x为0~1区间内10000个动态点
box on;
axis([0 1 0 100]);
hold on
m=0;
a=0;b=1;
for i=1:100
x = a + (b-a).*rand(100,1);
m=m+1;
y=log(x);
plot(x,m,‘r.‘)
pause(0.01)
frame=getframe(gcf);
imind=frame2im(frame);
[imind,cm] = rgb2ind(imind,256);
if i==1
imwrite(imind,cm,‘1234.gif‘,‘gif‘, ‘Loopcount‘,inf,‘DelayTime‘,1e-4);%第一次必须创建!
else
imwrite(imind,cm,‘1234.gif‘,‘gif‘,‘WriteMode‘,‘append‘,‘DelayTime‘,1e-4);
end
end
生成0~1区间10000个点的动态直方图分布
axis([0 1 0 800]);
hold on
a=0;b=1;
x=[];
n=[];
for i=1:100
m =(a + (b-a).*rand(100,1))‘;
x=[x(1:0) m x(1:end)];
y=-log(1-x);
[l,g]=hist(x,20);
hist(x,20)
h = findobj(gca,‘Type‘,‘patch‘);
set(h,‘facecolor‘,‘r‘);
pause(0.05);
end
在生成y=-ln(1-x)的动态散点
box on;
axis([0 8 0 100]);
hold on
m=0;
a=0;b=1;
for i=1:100
x = a + (b-a).*rand(100,1);
m=m+1;
y=-log(x);
plot(y,m,‘b.‘)
pause(0.01);
frame=getframe(gcf);
imind=frame2im(frame);
[imind,cm] = rgb2ind(imind,256);
if i==1
imwrite(imind,cm,‘12345.gif‘,‘gif‘, ‘Loopcount‘,inf,‘DelayTime‘,1e-4);%第一次必须创建!
else
imwrite(imind,cm,‘12345.gif‘,‘gif‘,‘WriteMode‘,‘append‘,‘DelayTime‘,1e-4);
end
end
生成y的动态直方图
axis([0 8 0 4000]);
hold on
a=0;b=1;
x=[];
n=[];
for i=1:100
m =(a + (b-a).*rand(100,1))‘;
x=[x(1:0) m x(1:end)];
y=-log(1-x);
hist(y,16)
h = findobj(gca,‘Type‘,‘patch‘);
set(h,‘facecolor‘,‘b‘);
pause(0.05);
end
生成x为3~5的散点和y位0.5x+0.1的动态散点图
box on;
axis([0 5 0 100]);
hold on
m=0;
a=3;b=5;
for i=1:100
x = a + (b-a).*rand(100,1);
m=m+1;
y=0.1*x+0.5;
plot(x,m,‘r.‘,y,m,‘b.‘)
pause(0.01);
frame=getframe(gcf);
imind=frame2im(frame);
[imind,cm] = rgb2ind(imind,256);
if i==1
imwrite(imind,cm,‘3.gif‘,‘gif‘, ‘Loopcount‘,inf,‘DelayTime‘,1e-4);%第一次必须创建!
else
imwrite(imind,cm,‘3.gif‘,‘gif‘,‘WriteMode‘,‘append‘,‘DelayTime‘,1e-4);
end
end
生成x为3~5的散点和y位0.5x+0.1的动态直方图
axis([0 5 0 1500]);
hold on
a=3;b=5;
x=[];
n=[];
for i=1:100
m =(a + (b-a).*rand(100,1))‘;
x=[x(1:0) m x(1:end)];
y=0.1*x+0.5;
hist(x,10)
h = findobj(gca,‘Type‘,‘patch‘);
set(h,‘facecolor‘,‘r‘);
hist(y,10)
set(gcf,‘outerposition‘,get(0,‘screensize‘))%设置最大化
frame=getframe(gcf);
imind=frame2im(frame);
[imind,cm] = rgb2ind(imind,256);
if i==1
imwrite(imind,cm,‘3.gif‘,‘gif‘, ‘Loopcount‘,inf,‘DelayTime‘,1e-4);%第一次必须创建!
else
imwrite(imind,cm,‘3.gif‘,‘gif‘,‘WriteMode‘,‘append‘,‘DelayTime‘,1e-4);
pause(0.01);
end
end
原文地址:https://www.cnblogs.com/liugangjiayou/p/11488398.html