matlab中waitbar使用
waitbar的作用是打开或者更新进度条。其语法结构有:
(1)h = waitbar(x,'message')
x表示进度条的比例长度,message是在进度条上显示的信息
(2)waitbar(x,'message','CreateCancelBtn','button_callback')%
通过制定CANCEL按键来终止程序运行。
(3)waitbar(x,'message',property_name,property_value,...)
(4)waitbar(x)
(5)waitbar(x,h)
(6)waitbar(x,h,'updated message')
通过(6)可以不断更新进度条上的信息,用来显示程序运行的进度。
例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
结束时可以使用close(h)关闭它。
例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