function delselection(h)

%% Deletes selected points and resets the selected status of deleted points

%% Get the data
xdata = h.Responses.DataSrc.Timeseries.Data;
ydata = h.Responses.DataSrc.Timeseries2.Data;

if strcmp(h.State,'DataSelect') && ...
    isequal(size(h.Responses.View.SelectedPoints),...
        [size(xdata,2) size(ydata,2) size(xdata,1)])
    
    % Create transaction and get the handle to the event recorder
    recorder = tsguis.recorder;
    T = tsguis.transaction;

    % Replace selected points with NaNs. Note that for >1x1 views the 
    % same observation may be referenced by multiple points: e.g.: 
    % points (1,1,10) and (2,1,10) both affect time series 2 at 
    % col 1 observation 10. If any of these points are marked for
    % deletion NaN replacement occurs at the corresponding point
    I = h.Responses.View.SelectedPoints;
    if ~isempty(I) && any(any(any(I)))
       I1 = squeeze(any(I,1));
       h.Responses.DataSrc.Timeseries.Data(I1') = NaN;
       I2 = squeeze(any(I,2));
       h.Responses.DataSrc.Timeseries2.Data(I2') = NaN;
       drawnow % Flush the event queue before activating
    end
    
    % Clear selected for deleted points
    h.Responses.View.SelectedPoints = [];

    % Store transaction
    T.commit;
    recorder.pushundo(T);

end
                  