我正在尝试修改此代码
h = waitbar(0,'Please wait...');
for i=1:10, % computation here % waitbar(i/10) end
close(h)
Run Code Online (Sandbox Code Playgroud)
如何将waitbar分成10个步骤.我的意思是它应该看起来像
-------------------
| | | | | | | | | |
-------------------
Run Code Online (Sandbox Code Playgroud)
以下代码允许您向等待栏添加垂直线:
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
Run Code Online (Sandbox Code Playgroud)
在运行上面的代码然后执行之后waitbar(0.35,hWait);,您将看到如下图:

注意:绘图中的黑线(我添加的垂直线和进度条周围已存在的框)将在更新时间歇性地出现在红色进度条的上方或下方.这似乎是WAITBAR行为的现有错误,我还没有找到解决方法来纠正它.但是,在MathWorks文件交换中可以找到很多替代方案,所以如果内置函数不能用于ya,我肯定会检查出来.;)