【发布时间】:2014-01-06 09:37:58
【问题描述】:
matlab 中是否可以有 2 个(多个)等待栏(进度条)? 就像一个窗口中有两个栏。
我知道我们可以使用用户定义的 GUI 来实现它并手动完成所有操作,但这将是一个漫长的过程。
【问题讨论】:
-
没有记录,内置
waitbar。但是还有其他选择,例如:stackoverflow.com/q/5368861/2319400
标签: matlab user-interface
matlab 中是否可以有 2 个(多个)等待栏(进度条)? 就像一个窗口中有两个栏。
我知道我们可以使用用户定义的 GUI 来实现它并手动完成所有操作,但这将是一个漫长的过程。
【问题讨论】:
waitbar。但是还有其他选择,例如:stackoverflow.com/q/5368861/2319400
标签: matlab user-interface
我推荐 Ben Tordoff 的 multiwaitbar,可在 MATLAB Central File Exchange 上找到。
【讨论】:
如果不是必须在同一个图形窗口中,则给等待栏句柄并通过句柄调用它们;例如
%% 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)
【讨论】:
delete(bar1) 和 delete(bar2) 不起作用。它还缺少一个重要功能取消按钮。