首页 > 代码库 > matlab学习---------------进度条waitbar
matlab学习---------------进度条waitbar
语法:
h = waitbar(x,‘message‘)
waitbar(x,‘message‘,‘CreateCancelBtn‘,‘button_callback‘)
waitbar(x,‘message‘,property_name,property_value,...)
waitbar(x) %将进度条进度改为新值
waitbar(x,h) %将句柄h的进度条进度改为x
waitbar(x,h,‘updated message‘) %更新进度条显示的进度和文字
实例1):h = waitbar(x,‘message‘)
h=waitbar(0.2,‘这是进度条‘);
结果:
实例2)waitbar(x,‘message‘,‘CreateCancelBtn‘,‘button_callback‘)
h=waitbar(0.9,‘点击cancel关闭进度条‘,‘CreateCancelBtn‘,‘close(h)‘)
结果:
实例3)修改进度条的颜色,可以使用get函数获得属性,然后修改:
hrand=waitbar(0.5,‘改变进度条颜色‘);
hal=get(hrand,‘children‘);
hac=get(hal,‘children‘);
hapa=findall(hac,‘type‘,‘patch‘);
set(hapa,‘facecolor‘,‘g‘)
结果:
实例4)改变进度和文字:waitbar(x,h,‘updated message‘)
h=waitbar(0.9,‘点击cancel关闭进度条‘,‘CreateCancelBtn‘,‘close(h)‘)
waitbar(0.1,‘改变后的文字‘)
结果:
实例5)综合实例,动态显示进度,进度完成之后自动关闭进度条
h = waitbar(0,‘Please wait...‘);
steps = 1000;
for step = 1:steps
% 进度条计算
waitbar(step / steps)
end
close(h)
结果: