我试图修改此代码Waitbar水平步骤,MATLAB
h = waitbar(0,'Please wait...');
for i=1:10, % computation here % waitbar(i/10) end
close(h)
我怎么能在10个步骤分为waitbar。我的意思是它应该看起来像
-------------------
| | | | | | | | | |
-------------------
我试图修改此代码Waitbar水平步骤,MATLAB
h = waitbar(0,'Please wait...');
for i=1:10, % computation here % waitbar(i/10) end
close(h)
我怎么能在10个步骤分为waitbar。我的意思是它应该看起来像
-------------------
| | | | | | | | | |
-------------------
下面的代码将允许你垂直线添加到您的waitbar:
hWait = waitbar(0,'Progress'); %# Create the waitbar and return its handle
hAxes = get(hWait,'Children'); %# Get the axes object of the waitbar figure
xLimit = get(hAxes,'XLim'); %# Get the x-axis limits
yLimit = get(hAxes,'YLim'); %# Get the y-axis limits
xData = repmat(linspace(xLimit(1),xLimit(2),11),2,1); %# X data for lines
yData = repmat(yLimit(:),1,11); %# Y data for lines
hLine = line(xData,yData,'Parent',hAxes,... %# Plot the lines on the axes...
'Color','k',... %# ... in black...
'HandleVisibility','off'); %# ... and hide the handles
运行上面的代码,然后做waitbar(0.35,hWait);
后,你会看到这样一个身影:
注:无刷交流绘图中的k条线(我在和框中已经存在的垂直线都会在进度条周围显示)会在更新时间间隔地出现在红色进度条的上方或下方。这看起来像是WAITBAR行为的现有错误,我还没有找到解决方法来纠正它。但是,在MathWorks File Exchange上有很多选择,所以如果内置函数不适用于ya,我一定会检查这些选项。 ;)
我不知道如何步骤添加到waitbar本身,但您可以添加,改变以显示如何计算有多少是完全动态的消息:
h = waitbar(0,'Please wait...0% complete');
for i = 1:10
% Computation here
waitbar(i/10, h, sprintf('Please wait...%d%% complete',100*(i/10)));
end
close(h);
由于waitbar
是一个低灵活性的内置函数,我认为没有简单的方法可以让waitbar看起来像你想要的那样。如果真的很重要,你可以在几种进度模式下绘制一个等待条并将其保存为图片。那么你可以加载一个简单的gui,看起来像一个等待吧! ;)
哟可以随时从零重新启动并更新消息。例如:
h = waitbar(0, 'Please wait...');
for step=1:10
waitbar(0, h, ['Step ' num2str(step) '/10 - Please wait...']);
for i=1:100
% Work...
waitbar(i/100, h);
end
end
Thanx,它工作正常。你也清除了另一个点。应该明确地解决这个问题。 – Shahgee 2011-05-25 19:48:48