Environment visible to timer callback function disppears after first iteration
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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 Comment
Kristoffer Walker
on 5 Dec 2019
Edited: Kristoffer Walker
on 5 Dec 2019
Answers (1)
Kristoffer Walker
on 6 Dec 2019
0 votes
1 Comment
Kristoffer Walker
on 6 Dec 2019
Edited: Kristoffer Walker
on 6 Dec 2019
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!