matlab进度条

<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);

结果如下:



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值