matlab进度条

来源:互联网 发布:平台软件下载 编辑:程序博客网 时间:2024/06/11 05:50
<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          endendif 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);endclose(h);

结果如下:



0 0
原创粉丝点击