2011-05-25 47 views
3

我試圖修改此代碼Waitbar水平步驟,MATLAB

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

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

我怎麼能在10個步驟分爲waitbar。我的意思是它應該看起來像

------------------- 
| | | | | | | | | | 
------------------- 

回答

5

下面的代碼將允許你垂直線添加到您的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);後,你會看到這樣一個身影:

enter image description here

注:無刷交流繪圖中的k條線(我在框中已經存在的垂直線都會在進度條周圍顯示)會在更新時間間隔地出現在紅色進度條的上方或下方。這看起來像是WAITBAR行爲的現有錯誤,我還沒有找到解決方法來糾正它。但是,在MathWorks File Exchange上有很多選擇,所以如果內置函數不適用於ya,我一定會檢查這些選項。 ;)

+0

Thanx,它工作正常。你也清除了另一個點。應該明確地解決這個問題。 – Shahgee 2011-05-25 19:48:48

1

我不知道如何步驟添加到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); 
0

由於waitbar是一個低靈活性的內置函數,我認爲沒有簡單的方法可以讓waitbar看起來像你想要的那樣。如果真的很重要,你可以在幾種進度模式下繪製一個等待條並將其保存爲圖片。那麼你可以加載一個簡單的gui,看起來像一個等待吧! ;)

2

喲可以隨時從零重新啓動並更新消息。例如:

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