function varargout = updategui(varargin)

%create a run time object that can return the value of the gain block's
%output and then put the value in a string

persistent plot_handle

Scope = get_param('DTS/Scope','RuntimeObject');

% create str from rto1
h1 = num2str(Scope.InputPort(3).Data);

% get a handle to the GUI's 'current state' window
display = findobj('Tag','edit_display');

% update the gui
set(display,'string',h1);

% Save Data to workspace
XData = get_param('DTS','SimulationTime');
YData = Scope.InputPort(3).Data;

assignin('base','XData',XData)
assignin('base','YData',YData)

if isempty(plot_handle) || ~ishandle(plot_handle)
    guiplot=findobj(0, 'Tag','axes1');
    plot_handle = plot(guiplot, XData, YData);
else
    XData_old = get(plot_handle, 'xdata');
    YData_old = get(plot_handle, 'ydata');
    XData = [XData_old, XData];
    YData = [YData_old, YData];
    set(plot_handle, 'XData', XData)
    set(plot_handle, 'YData', YData)
    axis([0 20 0 10])
    drawnow
end