Timer implementation in GUIDE
조회 수: 19 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Jan
2017년 3월 22일
편집: Jan
2017년 3월 22일
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
Jan
2017년 3월 29일
@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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!