Gui Guide Timer Stop and Start

4 visualizaciones (últimos 30 días)
Septimus Boshoff
Septimus Boshoff el 21 de Mzo. de 2020
Comentada: Septimus Boshoff el 24 de Mzo. de 2020
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);
  2 comentarios
Geoff Hayes
Geoff Hayes el 24 de Mzo. de 2020
Septimus - do you know which line of code correspods to the error? It is in the GUIUpdate callback function? Or is it at some other line?
Septimus Boshoff
Septimus Boshoff el 24 de Mzo. de 2020
It was this line -
get(t, 'Running') == 'off'

Iniciar sesión para comentar.

Respuesta aceptada

Septimus Boshoff
Septimus Boshoff el 24 de Mzo. de 2020
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)

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by