2013-12-18 2 views
4

matlab에 2 개의 (여러 개의) 대기 바 (진행 표시 줄)가있을 수 있습니까? 창에 두 개의 막대가있는 것과 같습니다.MATLAB에 두 개의 대기 바

우리는 사용자 정의 GUI를 사용하여 구현할 수 있으며 모든 것을 수동으로 처리 할 수 ​​있습니다.

+0

하지 문서화, 내장'waitbar'와. 그러나 대안이 있습니다. 예 : http://stackoverflow.com/q/5368861/2319400 – sebastian

답변

5

Ben Tordoff가 multiwaitbar을 추천합니다 (MATLAB Central File Exchange에서 사용 가능).

1

동일한 그림 창에있는 것이 중요하지 않은 경우 waitbars 핸들을 제공하고 핸들로 호출하십시오. 예 :

%% Script creating 2 wait bars in different windows 

bar1=waitbar(0,'bar1');   % creates 2 waitbars 
bar2=waitbar(0,'bar2'); 

% updates bar2 

waitbar(completed_value_bar2,bar2,'updated message') % updated message is optional 

% updates bar1 

waitbar(completed_value_bar1,bar1,'updated message') % updated message is optional 

% 
delete(bar1) 
delete(bar2) 

그것은 다음과 같은 방법을 사용하여 가능하다 필수적이다하지만 런타임을 증가하면 끔찍

%% Script creating 2 wait bars in the same figure window 


bar1=waitbar(0,'this is bar1','CreateCancelBtn','foo1'); 
bar2=waitbar(0,'this is bar2','CreateCancelBtn','foo2'); 
% foo1 represents function executed by cancel button 1 (similar for foo2) 

Pos=get(bar1,'OuterPosition');  
info_bar1=findobj(bar1);  % gets waitbar object handles 
info_bar2=findobj(bar2);  % 
set(bar1,'visible','off')  % hides the bars 
set(bar2,'visible','off')  % 
% generates intital figure window; 
F=figure; 
set(F,'position',[Pos(1:2),1.35*Pos(3),2*Pos(4)]); % resises figure (could be more elegant) 
loc1=get(info_bar1(2),'position');     % get position for bar1 
loc2=loc1+[0 50 0 0];        % shifts bar2 up 

P = copyobj(info_bar1(2),F); % Copy bar1 to new fig 

% note the figure handle bar1(2) contains the waitbar & message for bar1 

set(P,'position',loc1)   % Sets position of bar 1 
Q = copyobj(info_bar2(2),F); % Copy bar2 to new fig 
set(Q,'position',loc2)   % Sets position of bar 1 


button_loc1=get(info_bar1(3),'position'); % gets button location    
button_loc2=button_loc1+[0 50 0 0];   % shifts button 2 
B1 = copyobj(info_bar1(3),F);    % adds buttons to figure 
set(B1,'position',button_loc1)    % sets button location 
B2 = copyobj(info_bar2(3),F); 
set(B2,'position',button_loc2) 

% 
for a=1:100 

    for b=1:100 

     %some calculation 

     % updates bar2 
     completed_value_bar2=b/100; 
     waitbar(completed_value_bar2,bar2,'updated message') 
     delete(Q) 
     Q = copyobj(info_bar2(2),F); 
     set(Q,'position',loc2) 
    end 

    % updates bar1 
    completed_value_bar1=a/100; 
    waitbar(completed_value_bar1,bar1,'updated message') 
    delete(P) 
    P = copyobj(info_bar1(2),F); 
    set(P,'position',loc1) 

end 

% 
delete(bar1) 
delete(bar2) 
+0

코드는 많은 경험을 보여 주지만 마지막 두 줄'delete (bar1)'과'delete (bar2)'는 그렇지 않습니다. 작업. 또한 중요한 기능 ** 취소 버튼 **이 없습니다. – user263485

+0

새 이미지로 취소 버튼을 전송하는 방법을 아직 조사하지 않았습니다. delete 명령은 숨겨진 wait 막대를 삭제해야하지만 set (bar1, 'visable', 'on')으로 대체 (또는 선행) 한 경우 엄격하게 필수는 아니며 bar2의 경우와 마찬가지로 효과를 볼 수 있습니다. – RTL

+0

취소 버튼 (실행되는 코드 포함)은 info_bar1 및 info_bar2의 세 번째 항목이며, 위의 코드는 각 막대의 취소 버튼을 그림에 추가하는 것과 같이 편집됩니다 – RTL