I cannot access the handles in a timer callback function
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kelly Babitz
le 30 Juil 2017
Modifié(e) : Walter Roberson
le 30 Juil 2017
I have a GUI with a timer in it. I would like to be able to update a plot every .1 seconds, however, the timer function gives me the error:
Error while evaluating TimerFcn for timer 'timer-3'
Reference to non-existent field 'concMarker'
Can anyone help me fix this? I have been reading some other posts and people have been saying you need to update the handles structure, which I am not quite sure how to do (though when I have tried copying other people's code to do so it did not work either).
axis = findobj(PumpRateGuiDisplay,'Type','axes');
timerData = timer('TimerFcn',@timerFunction,...
'Period',.1,'ExecutionMode','FixedRate','BusyMode','Drop',...
'TasksToExecute',endTime*10 + 1,'Tag','timerData');
function timerFunction(hObject,eventData)
handles = guihandles(PumpRateGuiDisplay);
handles.cocnMarker = plot(axis,NaN,NaN,'r*');
timeElapsed = get(hObject,'TasksExecuted')-1;
if timeElapsed ~= 0
set(handles.concMarker,'XData',times(int64(timeElapsed*.1/timeIncrement)),'YData',concLeftVent(int64(timeElapsed*.1/timeIncrement)),'*');
end
end
Thanks in advance for the help!
0 commentaires
Réponse acceptée
Walter Roberson
le 30 Juil 2017
handles.cocnMarker = plot(axis,NaN,NaN,'r*');
set(handles.concMarker,'XData',times(int64(timeElapsed*.1/timeIncrement)),'YData',concLeftVent(int64(timeElapsed*.1/timeIncrement)),'*');
Compare the name of the handle carefully between those two lines.
4 commentaires
Walter Roberson
le 30 Juil 2017
Modifié(e) : Walter Roberson
le 30 Juil 2017
This was really obscure, and I had no idea that it happened.
I tend not to use imshow() because it changes too many properties for my liking, so I had never happened to encounter this before. It took digging.
I can see from the code that the behaviour is intended, but I filed a bug report anyhow to at least get it mentioned in the tips section.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!