Waitbar in horizontal steps, matlab
I am trying to modify this code
h = waitbar(0,'Please wait...');
for i=1:10, % computation here % waitbar(i/10) end
close(h)
How can I divide waitbar in 10 steps .开发者_开发技巧 I mean it should look like
-------------------
| | | | | | | | | |
-------------------
The following code will allow you to add vertical lines to your 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
After running the above code and then doing waitbar(0.35,hWait);
, you will see a figure like this:
NOTE: The black lines in the plot (both the vertical lines I added and the already existing box around the progress bar) will intermittently appear above or below the red progress bar when it is updated. This seems like an existing bug with how WAITBAR behaves, and I have yet to find a workaround to correct it. However, there are quite a number of alternatives that can be found on the MathWorks File Exchange, so I'd certainly check those out if the built-in function doesn't do it for ya. ;)
Yo can restart from zero at anytime and update the message. For instance:
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
I'm not sure how to add steps to the waitbar itself, but you can add a dynamic message that changes to show how much of the computation is complete:
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);
Since waitbar
is a built-in function with low flexibility, I think there is no simple way to make the waitbar look like that you want. If it really matters, you can draw a waitbar in several progress mode and save it as a picture. then you can load the pictures in a simple gui that looks like a waitbar! ;)
精彩评论