matlab 进度条/waitbar 显示运行进度

本文详细介绍MATLAB中waitbar函数的应用,包括如何创建及更新进度条,展示程序运行进度。并通过实例演示如何结合字符串格式化显示具体进度百分比。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当运行大程序,需要跑大量数据的时候,使用进度条可以看到程序究竟运行到什么地方了,哈哈,要不干等着难受(╯﹏╰)……

waitbar的作用是打开或者更新进度条。

1 语法结构

(1.1) h = waitbar(x,‘message’)

x表示进度条的比例长度,必须为0到1之间的数,message是在进度条上显示的信息

(1.2) waitbar(x,‘message’,‘CreateCancelBtn’,‘button_callback’)%

通过制定CANCEL按键来终止程序运行。
(1.3) waitbar(x,‘message’,property_name,property_value,…)
(1.4) waitbar(x)
(1.5) waitbar(x,h)
(1.6) waitbar(x,h,‘updated message’)

通过(1.6)可以不断更新进度条上的信息,用来显示程序运行的进度。

(2) 结束时可以使用delete(h)或close(h)关闭它。

h=waitbar(0,'please wait');
for i=1:1000
    %computation here%
    waitbar(i/1000,h)
end
delete(h);

在这里插入图片描述

如果要用数字显示运行进度,

h=waitbar(0,'please wait');

for i=1:1000
    %computation here%
    str=['运行中...',num2str(i/1000*100),'%'];
    waitbar(i/1000,h,str)
end
delete(h);

在这里插入图片描述

例1:

h = waitbar(0,'Simulation inprocess');
for i=1:1000
	s=sprintf('Simulation in process:%d',ceil(i/10));
	waitbar(i/1000,h,[s '%']);
end
h = waitbar(0,'Simulation inprocess');
for i=1:1000
	s=['Simulation in process:' num2str(ceil(i/10)) '%'];
	waitbar(i/1000,h,s);
end

仿真图:
在这里插入图片描述

2 给waitbar添加标题

h = waitbar(0,'1','name','Simulation');
for i=1:1000
	s=sprintf('Simulation in process:%d',ceil(i/10));
	waitbar(i/1000,h,[s '%']);
end

仿真图:
在这里插入图片描述

————————————————

原文链接:https://blog.csdn.net/MichaelPixer/article/details/55048754
http://blog.sina.com.cn/s/blog_acbf9f980102wma0.html
http://blog.sina.com.cn/s/blog_b2eaf2760101dyjn.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值