您的位置:首页 > 编程语言 > MATLAB

matlab进度条

2016-03-30 19:12 225 查看
<strong><span style="font-size:24px;">这是用matlab制作的进度条</span></strong>
</pre><pre name="code" class="plain">function h=mywaitbar(varargin)
%这是窗口内嵌的进度条
%
if nargin ==0
% %直接调用函数,默认创建
hWaitbar=waitbar(0,'嵌入式进度条','visible','off');
hAxes=findall(hWaitbar,'type','axes');
h_axes=copyobj(hAxes,gcf);
set(h_axes,'Units','pixels');
pos =get(h_axes,'position');
set(h_axes,'position',[10,10,pos(3:4)]);
else if nargin>1
x=varargin{1};
whichbar=varargin{2};
if(nargin==5)&&(ischar(whichbar)||iscell(whichbar))
hWaitbar=waitbar(x,whichbar,'visible','off');
hAxes=findall(hWaitbar,'type','axes');
h_axes=copyobj(hAxes,varargin{3});
set(h_axes,'Units','pixels');
pos =get(h_axes,'position');
set(h_axes,'position',[varargin{3},varargin{3},pos(3:4)]);
else if isnumeric(whichbar)
h_axes=whichbar;
hPatch=findobj(h_axes,'Type','patch');
set(hPatch,'XData',[0 100*x 100*x 0]);
if nargin==3
hTitle=get(h_axes,'title');
set(hTitle,'string',varargin{3});
end

else
error('input arguments error...');
end
end

end
end
if nargout==1
h=h_axes;
end
</pre><pre name="code" class="plain">
</pre><pre name="code" class="plain">
</pre><pre name="code" class="plain">
</pre><p>之后在命令行中输入:</p><p><pre name="code" class="html"> gca;
h=waitbar(0,'开始绘图...','WindowStyle','modal');
t=0:0.01:pi;
for i=1:10
plot(t,sin(2*pi*i*t));
waitbar(i/10,h,['已完成' num2str(10*i) '%']);
pause(1);
end
close(h);


结果如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: