【发布时间】:2012-06-16 18:02:54
【问题描述】:
不幸的是,我有两个循环。这就是为什么我的代码让第一个循环运行,并且只有在它完成后,它才会运行第二个循环。
但我希望 gui 同时显示数据:在 hAxes 和 loading1 中。
我该怎么做?
hFigure = figure('units','pixels','position',[300 300 424 470],'menubar','none',...
'name','start processing','numbertitle','off','resize','off');
hAxes = axes('Parent',hFigure,'Units','pixels','Position',[0 112 424 359]);
loading1 = uicontrol('style','text','unit','pix','position',[0 72 424 40],...
'backgroundcolor','r','fontsize',20);
%% shows the data on hAxes
for i = 5:100
if mod(i,2) == 0
set(hAxes,'Color','b');
else
set(hAxes,'Color','g');
end
drawnow;
end
%% shows the data on loading1
for i=1:200
image2 = horzcat('now processing ', 'image', num2str(i), '.jpg of 200 images');
set(loading1,'string',image2);
drawnow;
end
这段代码是彼得的:
function test1
hFigure = figure('units','pixels','position',[300 300 424 470],'menubar','none','name','start processing','numbertitle','off','resize','off');
% Your other setup calls
hAxes = axes('Parent',hFigure,'Units','pixels','Position',[0 112 424 359]);
loading1 = uicontrol('style','text','unit','pix','position',[0 72 424 40],'backgroundcolor','r','fontsize',20);
c = 1;
t = timer('TimerFcn', @color_change_fcn,'StartDelay',1.0);
start(t);
for i=1:200
image2 = horzcat('now processing ', 'image', num2str(i), '.jpg of 200 images');
set(loading1,'string',image2);
drawnow;
end
function color_change_fcn
if mod(c,2) == 0
set(hAxes,'Color','b');
else
set(hAxes,'Color','g');
end
drawnow;
c = c + 1;
end
end
它不起作用(不显示 hAxes)。我看到它没有使 color_change_fcn 运行(我试图在 color_change_fcn 函数的第一行写: disp('test') ,但它什么也没打印。
【问题讨论】:
-
您可以使用并行计算工具箱和 parfor 构造,但我建议您以某种方式将这两个循环结合起来,以便您具有确定性行为。
-
@Ansari,我知道我可以使用彼得在他的评论中写给我的内容,但我向他解释了原因。请阅读我对他的回答,并告诉我是否可以使用并行计算工具箱做到这一点。
标签: matlab user-interface simultaneous