Timer implementation in GUIDE
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I want to implement a timer which will plot continuously data on the gui. There are two push buttons, start and stop. "start" will start the ploting on axes. "stop" will stop the plotting on axes.
*Please find the attached files.
I am facing two issues while implementing it.
1) Initially I created a timer object and added it in handles structure(handles.timer2) and updated guidata. But when I call my Timer callback function (plot_data_callback), the handle of the timer is not preset in that timer callback function.
I created another timer object(timer1) and made it global. Now Global timer object is present in the Timer callback function (plot_data_callback).
I want to use timer2. can someone point out the error in declaring timer2? (I have uploaded guide files)
2) When Start is pressed, instead of plotting on axes it is creating another figure. I have declared the current axes for the plotting but it is not working.
Thank you in advance.
0 Commenti
Risposte (1)
Jan
il 22 Mar 2017
Modificato: Jan
il 22 Mar 2017
Avoid global variables. They cause troubles in general.
If you change the handles struct, care for writing the changes back to the figure. In the next callback, the handles struct from the input does not contain the last changes, so retrieve it directly from the figure again:
function callbackXYZ(hObject, EventData, handles_FromInput)
handles = guidata(hObject);
handles.XYZ = rand;
...
guidata(hObject, handles);
Then the handles struct is kept up-to-date between the different callbacks.
The handles of the timer is the first input of the TimerFcn. You do not need a global to get it.
Where is "handles.axes1" created? Perhaps you should create it in the OpeningFcn:
function timer_gui_OpeningFcn(...)
handles.axes1 = axes('Parent', hObject, 'NextPlot', 'add');
handles.hFigure = hObject; % Is this existing already?
guidata(hObject, handles);
Note that with "'Timerfcn',{@plot_data_callback,handles}" you define the 3rd input of the TimerFcn with the static value of the handles struct. If you want to access the current version stored in the figure, you have to retrieve it again in the timer callback:
function plot_data_callback(hObject, eventdata, handles_FromInputs)
hFigure = handles_FromInputs.hFigure;
handles = guidata(hFigure); % Current value
...
Then you should have access to the axes created inside the figure also.
5 Commenti
Jan
il 29 Mar 2017
@Akshay: I do not understand the sentence "I am not able to see timer's handle only in timer callback function". What does this mean? Please post the code and the error message.
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!