读书笔记(六)
这是第六部分绘图 主要通过绘制分形图案展示绘图命令 function fern shg %显示画图界面 clf reset %清楚当前所有子句柄 set(gcf,'color','white','menubar','none', ... 'numbertitle','off','name','Fractal Fern') % 相关设置:颜色、菜单栏、标题栏、名称 x = [.5; .5]; darkgreen = [0 2/3 0]; plot(x(1),x(2),'.','markersize',4,'color',darkgreen) axis([-3 3 0 10]) axis off %不显示座标轴 stop = uicontrol('style','toggle','string','stop', ... 'background','white'); % 设置一个停止按钮 % 空格加三个点是换行符 drawnow %立即绘图 hold on %保持窗体,否则会新建一个绘图 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) x = A1*x + b1; elseif r < p(2) x = A2*x + b2; elseif r < p(3) x = A3*x + b3; else x = A4*x; end plot(x(1),x(2),'.','markersize',4,'color',darkgreen) 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)') hold off