MATLAB GUI嵌入进度条(waitBar)

基本就是参考:http://www.ilovematlab.cn/thread-61732-1-1.html,改了点点方便用

function mywaitbar(x,num,varargin)
if nargin < 1
    error('Input arguments not valid');
end
fh = varargin{end};
set(0,'CurrentFigure',fh);
fAxestemp = findobj(fh,'type','axes')
fAxes = fAxestemp(num);
set(fh,'CurrentAxes',fAxes);
if nargin > 1
    hTitle = get(fAxes,'title');
    set(hTitle,'String',varargin{1});
end
fractioninput = x;
x = max(0,min(100*x,100));
if fractioninput == 0    
    cla
    xpatch = [0 x x 0];
    ypatch = [0 0 1 1];
    xline = [100 0 0 100 100];
    yline = [0 0 1 1 0];
    patch(xpatch,ypatch,'b','EdgeColor','b','EraseMode','none');
    set(fh,'UserData',fractioninput);
    l = line(xline,yline,'EraseMode','none');
    set(l,'Color',get(gca,'XColor'));   
else
    ptemp = findobj(fh,'Type','patch');
    p = ptemp(num);
    ltemp = findobj(fh,'Type','line');
    l = ltemp(num);
    if (get(fh,'UserData') > fractioninput)
        set(p,'EraseMode','normal');
    end
    xpatch = [0 x x 0];
    set(p,'XData',xpatch);
    xline = get(l,'XData');
    set(l,'XData',xline);  
end
drawnow;

调用的callback

mywaitbar(0,2,'Please Wait...',handles.figure1);
TheEndTime = 600; 
for t = 1:TheEndTime
       mywaitbar(t/TheEndTime,2,[num2str(floor(t*100/TheEndTime)),'%'],handles.figure1);
end

主要改的部分就是第二个参数,有尝试过直接传handles给mywaitbar,不过额。。。图省事。。。他里面是用findobj去查找这些handles的,所以直接用一个数去从返回的handles数组里面取一个就行了,这样就可以在多个axes图的GUI里面取选择让哪个axes去当做进度条来使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值