以下代码将允许您在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);,你会看到这样的图:
注意:图中的黑线(我添加的垂直线和进度条周围已经存在的框)将间歇性地出现在红色的上方或下方更新时的进度条。这似乎是 WAITBAR 行为方式的现有错误,我还没有找到解决方法来纠正它。但是,在MathWorks File Exchange 上可以找到很多替代品,所以如果内置功能不适合你,我肯定会检查一下。 ;)