Environment visible to timer callback function disppears after first iteration
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Folks,
I am fairly new to the timer object and its use. I have a timer GUI callback tied to a checkbox GUI element that looks like this:
period = str2double(get(handles.period, 'string'));
if (get(hObject, 'value'))
clear UpdateSimulation
set(handles.ViewReceivers, 'Enable', 'Off');
set(handles.ViewSources, 'Enable', 'Off');
set(handles.ViewModelEdges, 'Enable', 'Off');
set(handles.ViewSliceLines, 'Enable', 'Off');
set(handles.ViewTimeLine, 'Enable', 'Off');
set(handles.ViewGrid, 'Enable', 'Off');
set(handles.ViewPixels, 'Enable', 'Off');
set(handles.AGC, 'Enable', 'Off');
timerSim = timer;
timerSim.ExecutionMode = 'fixedRate';
timerSim.TasksToExecute = inf;
timerSim.Name = 'UpdateSimulationTimer';
timerSim.Period = period;
timerSim.TimerFcn = @(~,~)UpdateSimulation(handles);
timerSim.StopFcn = @DeleteUpdateSimulation;
handles.timerSim = timerSim;
guidata(hObject, handles);
start(timerSim);
else
stop(handles.timerSim);
clear handles.timerSim;
set(handles.ViewReceivers, 'Enable', 'On');
set(handles.ViewSources, 'Enable', 'On');
set(handles.ViewModelEdges, 'Enable', 'On');
set(handles.ViewSliceLines, 'Enable', 'On');
set(handles.ViewTimeLine, 'Enable', 'On');
set(handles.ViewGrid, 'Enable', 'On');
set(handles.ViewPixels, 'Enable', 'On');
set(handles.AGC, 'Enable', 'On');
end
Inside the UpdateSimulation function is this:
function handles = UpdateSimulation(handles)
persistent time dT cTime
if (isempty(dT))
% Start advancing automatically
time = handles.s.tXY;
dT = time(2)-time(1);
cTime = str2double(get(handles.Time, 'string'))*1e-3;
end
% Determine current time
cTime = cTime + dT;
set(handles.TimeSlider, 'value', cTime*1e3);
set(handles.Time, 'string', num2str(cTime*1e3));
handles = PlotSlices(handles, 1);
return
end
Inside PlotSlices is this:
function handles = PlotSlices(handles, iOpt)
handles = ViewTimeLine(handles);
return
end
Inside ViewTimeLine is this:
function handles = ViewTimeLine(handles)
findobj('type','figure')
return
end
The problem is that when this executes, I am expecting "findobj" in ViewTimeLine to see 4 figures. However, it only sees these 4 figures on the first iteration. Here is what I see. It seems the visibility of the 4 figures gets blocked somehow after the first iteration. What am I doing wrong?

Many thanks!
Kris
댓글 수: 1
Kristoffer Walker
2019년 12월 5일
편집: Kristoffer Walker
2019년 12월 5일
답변 (1개)
Kristoffer Walker
2019년 12월 6일
0 개 추천
댓글 수: 1
Kristoffer Walker
2019년 12월 6일
편집: Kristoffer Walker
2019년 12월 6일
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!