码迷,mamicode.com
首页 > 其他好文 > 详细

MATLAB小记_有趣的waitbar的用法

时间:2017-08-30 21:40:51      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:sim   程序   之一   运行   box   有趣   htm   建立   lan   

Matlab中的waitbar(进度条)的应用……(显示程序运行的百分比)

标签: 

杂谈

 
分类: Matlab

Matlab中的help“waitbar”得到应用之一:

h = waitbar(x,‘message‘);其中x必须为0到1之间的数,message为显示的信息,

举例如下:

hwait=waitbar(0,‘请等待>>>>>>>>‘);

得到:

技术分享
应用之二:

waitbar(x,h,‘updated message‘);

x为显示的进度,必须在0到1之间h为所建立的waitbar的句柄,updated message为实时显示的信息,此语句经常地用于for循环中,如下所示:

steps=100;
hwait=waitbar(0,‘请等待>>>>>>>>‘);
for k=1:steps
    if steps-k<=5
        waitbar(k/steps,hwait,‘即将完成‘);
        pause(0.05);
    else
        str=[‘正在运行中‘,num2str(k),‘%‘];
        waitbar(k/steps,hwait,str);
        pause(0.05);
    end
end
close(hwait); % 注意必须添加close函数

结果如下所示:

显示正在运行中:

技术分享

显示即将完成:

技术分享
上例子中,当循环步骤刚好是100,但是如果循环不是100的时候,要作小小的改变,举例如下:

steps=150;
hwait=waitbar(0,‘请等待>>>>>>>>‘);
step=steps/100;
for k=1:steps
    if steps-k<=5
        waitbar(k/steps,hwait,‘即将完成‘);
        pause(0.05);
    else
        PerStr=fix(k/step);
        str=[‘正在运行中‘,num2str(PerStr),‘%‘];
        waitbar(k/steps,hwait,str);
        pause(0.05);
    end
end
close(hwait);

结果如上面的所示。效果一致……

success……哈哈……

MATLAB小记_有趣的waitbar的用法

标签:sim   程序   之一   运行   box   有趣   htm   建立   lan   

原文地址:http://www.cnblogs.com/psztswcbyy/p/7455291.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!