Gui Guide Timer Stop and Start
조회 수: 11 (최근 30일)
이전 댓글 표시
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
Geoff Hayes
2020년 3월 24일
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?
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!