불행하게도 두 개의 루프가 있습니다. 이것이 내 코드가 첫 번째 루프를 실행하는 이유이며 두 번째 루프가 끝나면 완료됩니다.Matlab은 루프를 동시에 실행합니다.
그러나 나는 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
@Ansari, 나는 Peter가 그의 코멘트에서 쓴 것을 사용할 수 있음을 알고 있지만 그에게 이유를 설명합니다. 제 대답을 읽어 주시고 제가 병렬 컴퓨팅 도구 상자로 할 수 있는지 말해주십시오. –