我正试图修改此代码

h = waitbar(0,'Please wait...');

for i=1:10, % computation here %  waitbar(i/10) end
close(h)

我怎么能把酒吧分成十步呢我是说它应该看起来像
-------------------
| | | | | | | | | |
-------------------

最佳答案

以下代码将允许您在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上可以找到很多替代方案,所以如果内置函数不适合您,我肯定会检查这些方案;)

09-27 09:18