MATLAB: Gui Guide Timer Stop and Start

gui

Hi,
I have a gui which reads in data from a binary file and then plots it. I created a timer which should read the binary file and then updates the plot, however I run into an error when I would like to stop the timer and the updating. {Matrix dimensions must agree}. Starting the timer does not give an error
% --- Executes on button press in Start_Button.
function Start_Button_Callback(hObject, eventdata, handles)
t = handles.timer;
disp(t.Running);
if get(t, 'Running') == 'off'
start(handles.timer);
elseif get(t, 'Running') == 'on'
disp('xfdgh');
stop(handles.timer);
end
pause(0.5)
function GUIUpdate(obj,event,handles)
global x y1 y2
Window_buffer_Matrix = read_bin_file(Rows_in_database, ...
Dynamic_Database_buffer_size); % a function that reads in the data into a matrix
[~, cols_of_data] = size(Window_buffer_Matrix);
if cols_of_data > 0 && x(1,1) ~= Window_buffer_Matrix(1,1)
x = Window_buffer_Matrix(1,1:cols_of_data); % the x axis data
y1 = Window_buffer_Matrix(2,1:cols_of_data); % plotting two sets of data on one axis
y2 = Window_buffer_Matrix(2 + i,1:cols_of_data);
handles.plot = plot(handles.axes1,x,y1, 'b',...
1 + x, y2, '-.r'); % y2 is the forecasted values of y1, hence x + 1
end
end
function gui_OpeningFcn(hObject, eventdata, handles, varargin)
global y1 y2 x
x = 0;
y1 = 0;
y2 = 0;
handles.plot = plot(handles.axes1,x,y1, 'b',...
1 + x, y2, '-.r');
axes(handles.axes1);
ylabel('VRMS [pu]');
xlabel('Time step');
ylim([0.95 1.05]);
legend('Actual','Predicted')
title('Voltage Magnitude');
grid on;
handles.timer = timer('ExecutionMode','fixedRate',...
'Period', 0.5,...
'TimerFcn', {@GUIUpdate,handles});
handles.output = hObject;
guidata(hObject, handles);

Best Answer

I found the solution!
function Start_Button_Callback(hObject, eventdata, handles)
tick_tock = handles.timer;
run = tick_tock.Running;
if strcmp(run,'off')
disp('Timer Started');
start(handles.timer);
set(handles.Start_Button,'string','Stop');
elseif strcmp(run,'on')
disp('Timer Stopped');
stop(handles.timer);
set(handles.Start_Button,'string','Start');
end
pause(0.5)
Related Question