Contents

INITIALIZE GUI

back to top
Oops...
%```````````````````````````````````````````````
function varargout = EditEvents(varargin)
% EDITEVENTS MATLAB code for EditEvents.fig
%      EDITEVENTS, by itself, creates a new EDITEVENTS or raises the existing
%      singleton*.
%
%      H = EDITEVENTS returns the handle to a new EDITEVENTS or the handle to
%      the existing singleton*.
%
%      EDITEVENTS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in EDITEVENTS.M with the given input arguments.
%
%      EDITEVENTS('Property','Value',...) creates a new EDITEVENTS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before EditEvents_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to EditEvents_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help EditEvents

% Last Modified by GUIDE v2.5 12-May-2014 10:49:09

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @EditEvents_OpeningFcn, ...
                   'gui_OutputFcn',  @EditEvents_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before EditEvents is made visible.
function EditEvents_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to EditEvents (see VARARGIN)

% Choose default command line output for EditEvents
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% Clear workspace
evalin('base','clear all; clc')

% Initialize Variables
evalin('base','mydirChoose = pwd;');
% clear axes 1
cla(handles.axes1,'reset');
set(handles.axes1,'visible','off')
axis off;
% clear axes 2
cla(handles.axes2,'reset');
set(handles.axes2,'visible','off')
axis off;
% clear axes 3
cla(handles.axes3,'reset');
set(handles.axes3,'visible','off')
axis off;


% ADD SPECIFIC FOLDERS TO SEARCH PATH CONTAINING RAW DATA, ABF FILES
rawDataPaths %call function to add paths


% UIWAIT makes EditEvents wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = EditEvents_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


%```````````````````````````````````````````````

SLIDER SELECTION

back to top
%```````````````````````````````````````````````
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
%
% Get slider position
slider1pos = round(get(handles.slider1,'Value')); %get slider position
k = slider1pos;

% Activate pointer manager
iptPointerManager(handles.figure1);
% Show busy pointer
set(handles.figure1,'Pointer','watch');
pause(0.2); %draw

% Get variables for updating axes
y2 = evalin('base','y2'); %load filtered signal
myEvents = evalin('base','myEvents'); %load myEvents
myEventsFlag = evalin('base','myEventsFlag'); %load myEventsFlag

si = evalin('base','si'); %load sample interval from base workspace


Eventplot = y2(myEvents(k,1):myEvents(k,3)); %get event to be plotted
mintemp = min(Eventplot);
Eventplot = Eventplot - mintemp; %translate signal to origin

assignin('base','Eventplot',Eventplot);

if myEventsFlag(k) == 1

    % Generate time series x-axis
    xRD = (1:length(Eventplot))*si; %get x-vector in time units
    % Plot in axes1
    plot(handles.axes1,xRD,Eventplot,'r.')

    % Disable Pointer Manager
    set(handles.figure1,'Pointer','arrow');
    iptPointerManager(handles.figure1, 'disable')

    % Make axes1 non visible
    set(handles.axes1,'visible','off')
    axis off;
    % clear axes 2
    cla(handles.axes2,'reset');
    set(handles.axes2,'visible','off')
    axis off;
    % clear axes 3
    cla(handles.axes3,'reset');
    set(handles.axes3,'visible','off')
    axis off;

    % Update display of text1
    set(handles.text1,'String',['Event ',num2str(NaN)])

else
    % resample curve and plot resampled curve, use myresample_simple
    [yRis yDec yRes siNew] = myResample_simple_extend(y2,myEvents(k,1),myEvents(k,3),si,(si/0.0001));
    mintemp = min(yRis);
    yRis = yRis - mintemp;
    mintemp = min(yDec);
    yDec = yDec - mintemp;

    % Generate time series x-axis
    xR = (1:length(yRis))*siNew; %get x-vector in time units
    xD = (1:length(yDec))*siNew; %get x-vector in time units
    xRD = (1:length(Eventplot))*si; %get x-vector in time units

    % Plot data
    handles.axes1_plot1 = plot(handles.axes1,xRD,Eventplot,'k.'); %plot in axes1
    handles.axes2_plot1 = plot(handles.axes2,xR,yRis,'k.'); %plot rising leg in axes2
    handles.axes3_plot1 = plot(handles.axes3,xD,yDec,'k.'); %plot rising leg in axes2

    % Count good Events up to any point in array
    cgE = ~myEventsFlag(1:k); %take the logical opposite up to slider position
    cbE = length(cgE); cgE = sum(cgE); %count events,  %sum the logical opposite
    % Update display of text1
    set(handles.text1,'String',['Event (Good/Total): ',num2str(cgE), ' / ', num2str(cbE)])

    % Change Pointer
    set(handles.figure1,'Pointer','arrow');

    % Axes assign the callback to axes buttondownFcn b/c when you plot on an axes that has the nextplot property set to replace, all callbacks, etc are reset in that call
    axes1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
    set(handles.axes1,'ButtonDownFcn',axes1_buttonDownFcn_String); %set buttondown callback

    % Plot1 assign callback to buttondownFcn
    axes1_plot1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
    set(handles.axes1_plot1,'ButtonDownFcn',axes1_plot1_buttonDownFcn_String); %set buttondown callback

    % Change cursor object when in axes1
%     axes1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_pointer_Fcn',hObject,eventdata,guidata(hObject));
    iptSetPointerBehavior(handles.axes1, @axes1_pointer_Fcn)

    % Change cursor object when in object1
%     axes1_plot1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_pointer_Fcn',hObject,eventdata,guidata(hObject));
    iptSetPointerBehavior(handles.axes1_plot1, @axes1_plot1_pointer_Fcn)


end

%///////////////////////////////////////////////


%```````````````````````````````````````````````

OPEN FOLDER

back to top
%```````````````````````````````````````````````
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% get directory and save for future use
%
% Select Folder
mydircheck = evalin('base','exist(''mydirChoose'',''var'');');
if mydircheck == 0
    mydirChoose = pwd;
else
    mydirChoose = evalin('base','mydirChoose'); %get previously selected path
end

% Get folder path
mydirChoose = uigetdir(mydirChoose); %get path to chosen directory

% if no folder selected return to gui
if mydirChoose == 0
    msgbox('Select a folder')
    return;
end

% Save mydirChoose to workspace
assignin('base','mydirChoose',mydirChoose); %save variable to workspace

% Fill static text box
parsemypath = strfind(mydirChoose,'\'); %get all indices where '\' exists
myfolder = mydirChoose(parsemypath(end)+1:end); %get all info after last '\'
set(handles.text2,'string',myfolder); %info after last '\' is folder name

% Modify button state
set(handles.pushbutton2,'Enable','on'); % enable open file

% clear axes 1
cla(handles.axes1,'reset');
set(handles.axes1,'visible','off')
axis off;
% clear axes 2
cla(handles.axes2,'reset');
set(handles.axes2,'visible','off')
axis off;
% clear axes 3
cla(handles.axes3,'reset');
set(handles.axes3,'visible','off')
axis off;
%///////////////////////////////////////////////


%```````````````````````````````````````````````

OPEN FILE

back to top
Oops...
%```````````````````````````````````````````````
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Load directory variable and use to navigate to folder
%
% Get file from user
mypwd = evalin('base','pwd'); % get current directory
mydirChoose = evalin('base','mydirChoose');
Eventsfile = uigetfile({'*autoEventStats.mat',  'autoEventStats Files (*autoEventStats.mat)'},...
    'Select Electrophys AutoEventDataStats File', [mydirChoose,'/']);

% if no file selected or file not .abf exit function
if isempty(strfind(Eventsfile,'autoEventStats.mat'))
    if Eventsfile == 0
        msgbox('Select autoEventStats.mat file')
    end
    return;
end

% Reset Axes1
cla(handles.axes1,'reset')
set(handles.axes1,'Visible','off')

% Activate pointer manager
iptPointerManager(handles.figure1);
set(handles.figure1,'Pointer','watch'); % Show busy pointer

% Move pointer
axes1_h_obj = handle(handles.axes1);
moveptr(axes1_h_obj,'init')
moveptr(axes1_h_obj,'move',0.4,0.6)

% Display busy
axes(handles.axes1);
h_text = text(0.5,0.5,' Busy ','FontSize',14,'HorizontalAlignment','center',...
    'BackgroundColor',[.8 .3 .05]);

pause(.2) % draw

% Create variables
assignin('base','Eventsfile',Eventsfile); %write to workspace

%Eventsfile = name of the '_autoEventStats.mat' file
cellnameidx = strfind(Eventsfile,'_autoEventStats.mat'); % find index in file name where '_autoEventStats.mat' begins
cellname = Eventsfile(1:cellnameidx(end)-1); % cellname is all string data before last index of '_'
abfFile = [cellname,'.abf']; % generate the name of the associated .abf file

% Copy file to current directory
copyfile([mydirChoose,'\',Eventsfile],Eventsfile) % copy .mat file

% Load .mat to workspace
evalin('base','load([pwd, ''\'', Eventsfile])'); % load data in '_autoEventStats.mat' file
delete([mypwd, '\', Eventsfile]) %remove when done

% Check if autoEventStats.mat stored fileCorrupt
fileCorrupt = evalin('base','exist(''fileCorrupt'',''var'')');
if fileCorrupt == 1
    msgbox('File Corrupt, no events')
    evalin('base','clear fileCorrupt');
    % Show normal pointer
    set(h_text,'string','Complete','BackgroundColor',[.7 .9 .7])
    set(handles.figure1,'Pointer','arrow');
    return;
end

% Make backups of editable variables
evalin('base','myEvents_copy = myEvents;');
evalin('base','myEventsFlag_copy = myEventsFlag;');

% Update static text3
set(handles.text3,'string',cellname);

% load .abf to workspace
[mycell si] = abfload(abfFile); % load abf file and sample interval, 'si'
si = si/1e6; % convert sample interval usec to sec
mycell = myFilter(mycell); % filter signal

% determine if signal needs to be cropped
limitsCrop = evalin('base','limitsCrop');
if isempty(limitsCrop)
    y1 = mycell;
else
    y1 = mycell(limitsCrop(1):limitsCrop(2));
end
y2 = y1;
assignin('base','y2',y2); %write to workspace

% Plot the first Event in window
myEvents = evalin('base','myEvents'); %load myEvents
myEventsFlag = evalin('base','myEventsFlag'); %load myEventsFlag
Eventplot = y2(myEvents(1,1):myEvents(1,3)); %get 1st event to be plotted
mintemp = min(Eventplot);
Eventplot = Eventplot - mintemp; %translate event to origin
% Generate time series x-axis
xRD = (1:length(Eventplot))*si; %get x-vector in time units

if myEventsFlag(1) == 1
    % Show normal pointer
    set(h_text,'string','Complete','BackgroundColor',[.7 .9 .7])
    set(handles.figure1,'Pointer','arrow');

    % Plot in axes1
    plot(handles.axes1,xRD,Eventplot,'r.')

    % Disable Pointer Manager
    iptPointerManager(handles.figure1, 'disable')

    % Make axes1 non visible
    set(handles.axes1,'visible','off')
    axis off;
    % clear axes 2
    cla(handles.axes2,'reset');
    set(handles.axes2,'visible','off')
    axis off;
    % clear axes 3
    cla(handles.axes3,'reset');
    set(handles.axes3,'visible','off')
    axis off;

    % Update display of text1
    set(handles.text1,'String',['Event ',num2str(NaN)])

else
    % resample curve and plot resampled curve, use myresample_simple
    [yRis yDec yRes siNew] = myResample_simple_extend(y2,myEvents(1,1),myEvents(1,3),si,(si/0.0001));
    mintemp = min(yRis);
    yRis = yRis - mintemp;
    mintemp = min(yDec);
    yDec = yDec - mintemp;

    % Show normal pointer
    set(h_text,'string','Complete','BackgroundColor',[.7 .9 .7])
    set(handles.figure1,'Pointer','arrow');

    % Generate time series x-axis
    xR = (1:length(yRis))*siNew; %get x-vector in time units
    xD = (1:length(yDec))*siNew; %get x-vector in time units
    xRD = (1:length(Eventplot))*si; %get x-vector in time units

    % Plot data
    handles.axes1_plot1 = plot(handles.axes1,xRD,Eventplot,'k.'); %plot in axes1
    handles.axes2_plot1 = plot(handles.axes2,xR,yRis,'k.'); %plot rising leg in axes2
    handles.axes3_plot1 = plot(handles.axes3,xD,yDec,'k.'); %plot rising leg in axes2

    % Assign the callback to axes buttondownFcn b/c when you plot on an axes that has the nextplot property set to replace, all callbacks, etc are reset in that call
    axes1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
    set(handles.axes1,'ButtonDownFcn',axes1_buttonDownFcn_String); %set buttondown callback

    % Plot1 assign callback to buttondownFcn
    axes1_plot1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
    set(handles.axes1_plot1,'ButtonDownFcn',axes1_plot1_buttonDownFcn_String); %set buttondown callback

    % Activate pointer manager
    iptPointerManager(handles.figure1);

    % Change cursor object when in axes1
    axes1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_pointer_Fcn',hObject,eventdata,guidata(hObject));
    iptSetPointerBehavior(handles.axes1, axes1_pointer_Fcn_String)

    % Change cursor object when in object1
    axes1_plot1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_pointer_Fcn',hObject,eventdata,guidata(hObject));
    iptSetPointerBehavior(handles.axes1_plot1, axes1_plot1_pointer_Fcn_String)

    % Count good Events up to any point in array
    cgE = ~myEventsFlag(1); %take the logical opposite up to slider position
    cbE = length(cgE); cgE = sum(cgE); %count events,  %sum the logical opposite

    % Update display of text1
    set(handles.text1,'String',['Event (Good/Total): ',num2str(cgE), ' / ', num2str(cbE)])

end

% Initialize slider1
mymax = size(myEvents,1); mymin = 1;
mystep = [1, 0.2*(mymax-mymin)]*1/(mymax-mymin); %increment slider fractions of #frames: [1/#frame 20%#frames]
set(handles.slider1,'Min',mymin);
set(handles.slider1,'Max',(mymax));
set(handles.slider1,'SliderStep', mystep);
set(handles.slider1,'Value',1);
set(handles.slider1,'interruptible','off');

% Enable slider1
set(handles.slider1,'Enable','on') %enable slider
%///////////////////////////////////////////////


%```````````````````````````````````````````````

SAVE

back to top
%```````````````````````````````````````````````
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%
% Verify Save
q_save = questdlg('Verify Save ', ...
 'Saving', ...
 'Yes' ,'No' ,'Cancel' ,'Yes');
% Handle response

if strcmp(q_save,'Yes')
    mydirChoose = evalin('base','mydirChoose');
    Eventsfile = evalin('base','Eventsfile'); %get variable from base workspace
    evalin('base',...
    'save(Eventsfile,''EventDataStats'', ''limitsCrop'', ''myEvents'',''myEventsFlag'', ''peakSet'', ''peakThreshold'', ''si'');');
    % move statistics file to mydirChoose
    movefile(Eventsfile,mydirChoose); % move Stats file to search folder
    msgbox('File Saved','EventStats','help'); %display confirmation message in window

else return

end
%///////////////////////////////////////////////


%```````````````````````````````````````````````

FLAG

back to top
%```````````````````````````````````````````````
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

myEventsFlag = evalin('base','myEventsFlag');
slider1pos = round(get(handles.slider1,'Value')); %get slider position
k = slider1pos;

myEventsFlag(k) = 1;
assignin('base','myEventsFlag',myEventsFlag);

%Update axes1
y2 = evalin('base','y2'); %load filtered signal
myEvents = evalin('base','myEvents'); %load myEvents
si = evalin('base','si'); %load sample interval from base workspace

Eventplot = y2(myEvents(k,1):myEvents(k,3));
% Generate time series x-axis
xRD = (1:length(Eventplot))*si; %get x-vector in time units

if myEventsFlag(k) == 1

    % Plot in axes1
    plot(handles.axes1,xRD,Eventplot,'r.')

    % Disable Pointer Manager
    iptPointerManager(handles.figure1, 'disable')

    % Make axes1 non visible
    set(handles.axes1,'visible','off')
    axis off;
    % clear axes 2
    cla(handles.axes2,'reset');
    set(handles.axes2,'visible','off')
    axis off;
    % clear axes 3
    cla(handles.axes3,'reset');
    set(handles.axes3,'visible','off')
    axis off;

    % Update display of text1
    set(handles.text1,'String',['Event ',num2str(NaN)])

end
%///////////////////////////////////////////////


%```````````````````````````````````````````````

UNFLAG

back to top
%```````````````````````````````````````````````
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
myEventsFlag = evalin('base','myEventsFlag');
slider1pos = round(get(handles.slider1,'Value')); %get slider position
k = slider1pos;

myEventsFlag(k) = 0;
assignin('base','myEventsFlag',myEventsFlag);

%Update axes1
y2 = evalin('base','y2'); %load filtered signal
myEvents = evalin('base','myEvents'); %load myEvents

si = evalin('base','si'); %load sample interval from base workspace


% resample curve and plot resampled curve, use myresample_simple
[yRis yDec yRes siNew] = myResample_simple_extend(y2,myEvents(k,1),myEvents(k,3),si,(si/0.0001));

Eventplot = y2(myEvents(k,1):myEvents(k,3));
% Eventplot = y2(myEvents(k,1):myEvents(k,3)); %get event to be plotted
mintemp = min(Eventplot);
Eventplot = Eventplot - mintemp; %translate signal to origin
mintemp = min(yRis);
yRis = yRis - mintemp;
mintemp = min(yDec);
yDec = yDec - mintemp;

% Generate time series x-axis
xR = (1:length(yRis))*siNew; %get x-vector in time units
xD = (1:length(yDec))*siNew; %get x-vector in time units
xRD = (1:length(Eventplot))*si; %get x-vector in time units

% Plot data
handles.axes1_plot1 = plot(handles.axes1,xRD,Eventplot,'k.'); %plot in axes1
handles.axes2_plot1 = plot(handles.axes2,xR,yRis,'k.'); %plot rising leg in axes2
handles.axes3_plot1 = plot(handles.axes3,xD,yDec,'k.'); %plot rising leg in axes2

% Axes assign the callback to axes buttondownFcn b/c when you plot on an axes that has the nextplot property set to replace, all callbacks, etc are reset in that call
axes1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
set(handles.axes1,'ButtonDownFcn',axes1_buttonDownFcn_String); %set buttondown callback

% Plot1 assign callback to buttondownFcn
axes1_plot1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
set(handles.axes1_plot1,'ButtonDownFcn',axes1_plot1_buttonDownFcn_String); %set buttondown callback

% Activate pointer manager
iptPointerManager(handles.figure1);

% Change cursor object when in axes1
axes1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_pointer_Fcn',hObject,eventdata,guidata(hObject));
iptSetPointerBehavior(handles.axes1, axes1_pointer_Fcn_String)

% Change cursor object when in object1
axes1_plot1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_pointer_Fcn',hObject,eventdata,guidata(hObject));
iptSetPointerBehavior(handles.axes1_plot1, axes1_plot1_pointer_Fcn_String)

% Count good Events up to any point in array
cgE = ~myEventsFlag(1:k); %take the logical opposite up to slider position
cbE = length(cgE); cgE = sum(cgE); %count events,  %sum the logical opposite
% Update display of text1
set(handles.text1,'String',['Event (Good/Total): ',num2str(cgE), ' / ', num2str(cbE)])
%///////////////////////////////////////////////


%```````````````````````````````````````````````

HOVER OVER AXES

back to top
%```````````````````````````````````````````````
% --- Executes on .
function axes1_pointer_Fcn(hObject, eventdata, handles)
% hObject    handle to  (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(hObject,'Pointer','fullcross');
%///////////////////////////////////////////////


%```````````````````````````````````````````````

HOVER OVER OBJECT1 IN AXES

back to top
%```````````````````````````````````````````````
% --- Executes on .
function axes1_plot1_pointer_Fcn(hObject, eventdata, handles)
% hObject    handle to  (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(hObject,'Pointer','fullcrosshair');
%///////////////////////////////////////////////


%```````````````````````````````````````````````

CLICK ON OBJECT IN AXES

back to top
%```````````````````````````````````````````````
% --- Executes on .
function axes1_plot1_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to  (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%
% Get the axes and figure positions in pixesl units
axes_Units = get(get(hObject,'Parent'),'Units'); %get the current units
set(get(hObject,'Parent'),'Units','Pixels') %when left as pixels, scaling does not work
axes_pos = get(get(hObject,'Parent'),'Position'); %get position in pixels
set(get(hObject,'Parent'),'Units',axes_Units); %set back to original state

Fig1_Units = get(handles.figure1,'Units'); %get the current units
set(handles.figure1,'Units','Pixels') %when left as pixels, scaling does not work
Fig1_cp = get(handles.figure1,'CurrentPoint'); %get position in pixels
set(handles.figure1,'Units',Fig1_Units); %set back to original state

% Get parameter of axes1 and plot1
axes_xL = get(get(hObject,'Parent'),'XLim'); %get axes1 x plot limit
axes_yL = get(get(hObject,'Parent'),'YLim'); %get axes1 y plot limit
plot1_xD = get(hObject,'XData'); %get Xdata vector

% Determine index nearest Fig1_cp
cp_pos_temp = ( (Fig1_cp(1) - axes_pos(1) +1) * (axes_xL(2)/axes_pos(3)) ); %find relative x-axis value - as a fraction of x-axis limit
[~,cp_pos] = min( (plot1_xD - cp_pos_temp).^2 ); %get position by min square error
cp_pos = cp_pos(1); %get fist entry in case clicked at midpoint

% Update axes1 at nearest point clicked
npt_x = plot1_xD(cp_pos); %get x data value
hold all;
axes(get(hObject,'Parent'))
line('XData',[npt_x npt_x],'YData',axes_yL,'Color','r');
hold off;

pause(0.2)

% Update myEvents
myEvents = evalin('base','myEvents');
slider1pos = round(get(handles.slider1,'Value')); %get slider position
k = slider1pos;

% determine location of cp_pos and trim left or right legs of event
if cp_pos < myEvents(k,2)-myEvents(k,1)+1
    myEvents(k,1) = myEvents(k,1) + cp_pos - 1;
else
    myEvents(k,3) = myEvents(k,1) + cp_pos - 1;
end

assignin('base','myEvents',myEvents); %update in base workspace

%Update axes1
y2 = evalin('base','y2'); %load filtered signal
myEvents = evalin('base','myEvents'); %load myEvents
myEventsFlag = evalin('base','myEventsFlag'); %load myEvents

si = evalin('base','si'); %load sample interval from base workspace

% resample curve and plot resampled curve, use myresample_simple
[yRis yDec yRes siNew] = myResample_simple_extend(y2,myEvents(k,1),myEvents(k,3),si,(si/0.0001));

Eventplot = y2(myEvents(k,1):myEvents(k,3));
% Eventplot = y2(myEvents(k,1):myEvents(k,3)); %get event to be plotted
mintemp = min(Eventplot);
Eventplot = Eventplot - mintemp; %translate signal to origin
mintemp = min(yRis);
yRis = yRis - mintemp;
mintemp = min(yDec);
yDec = yDec - mintemp;

% Generate time series x-axis
xR = (1:length(yRis))*siNew; %get x-vector in time units
xD = (1:length(yDec))*siNew; %get x-vector in time units
xRD = (1:length(Eventplot))*si; %get x-vector in time units

% Plot data
handles.axes1_plot1 = plot(handles.axes1,xRD,Eventplot,'k.'); %plot in axes1
handles.axes2_plot1 = plot(handles.axes2,xR,yRis,'k.'); %plot rising leg in axes2
handles.axes3_plot1 = plot(handles.axes3,xD,yDec,'k.'); %plot rising leg in axes2

% Axes eassign the callback to axes buttondownFcn b/c when you plot on an axes that has the nextplot property set to replace, all callbacks, etc are reset in that call
axes1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
set(handles.axes1,'ButtonDownFcn',axes1_buttonDownFcn_String); %set buttondown callback

% Plot1 assign callback to buttondownFcn
axes1_plot1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
set(handles.axes1_plot1,'ButtonDownFcn',axes1_plot1_buttonDownFcn_String); %set buttondown callback

% Activate pointer manager
iptPointerManager(handles.figure1);

% Change cursor object when in axes1
axes1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_pointer_Fcn',hObject,eventdata,guidata(hObject));
iptSetPointerBehavior(handles.axes1, axes1_pointer_Fcn_String)

% Change cursor object when in object1
axes1_plot1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_pointer_Fcn',hObject,eventdata,guidata(hObject));
iptSetPointerBehavior(handles.axes1_plot1, axes1_plot1_pointer_Fcn_String)

% disp('Clicked Data Point')
% disp(['Nearest point ', num2str(cp_pos)])

% Count good Events up to any point in array
cgE = ~myEventsFlag(1:k); %take the logical opposite up to slider position
cbE = length(cgE); cgE = sum(cgE); %count events,  %sum the logical opposite
% Update display of text1
set(handles.text1,'String',['Event (Good/Total): ',num2str(cgE), ' / ', num2str(cbE)])
%///////////////////////////////////////////////


%```````````````````````````````````````````````

CLICK IN AXES

back to top
%```````````````````````````````````````````````
% --- Executes on .
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%
% Get the axes and figure positions in pixesl units
axes_Units = get(hObject,'Units'); %get the current units
set(hObject,'Units','Pixels') %when left as pixels, scaling does not work
axes_pos = get(hObject,'Position'); %get position in pixels
set(hObject,'Units',axes_Units); %set back to original state

Fig1_Units = get(handles.figure1,'Units'); %get the current units
set(handles.figure1,'Units','Pixels') %when left as pixels, scaling does not work
Fig1_cp = get(handles.figure1,'CurrentPoint'); %get position in pixels
set(handles.figure1,'Units',Fig1_Units); %set back to original state

% Get parameter of axes1 and plot1
axes_xL = get(hObject,'Xlim'); %get axes plot limit
axes_yL = get(hObject,'YLim'); %get axes1 y plot limit
axes_Children = get(hObject,'Children'); % get axes1 children
plot1_xD = get(axes_Children(end),'Xdata'); %get Xdata vector, last entry in children list is first object plotted in axes

% Determine index nearest Fig1_cp
cp_pos_temp = ( (Fig1_cp(1) - axes_pos(1) +1) * (axes_xL(2)/axes_pos(3)) ); %find relative x-axis value - as a fraction of x-axis limit
[~,cp_pos] = min( (plot1_xD - cp_pos_temp).^2 ); %get position by min square error
cp_pos = cp_pos(1); %get fist entry in case clicked at midpoint

% Update axes1 at nearest point clicked
npt_x = plot1_xD(cp_pos); %get x data value
hold all;
axes(hObject)
line('XData',[npt_x npt_x],'YData',axes_yL,'Color','r');
hold off;

pause(0.2)

% Update myEvents
myEvents = evalin('base','myEvents');
slider1pos = round(get(handles.slider1,'Value')); %get slider position
k = slider1pos;

% determine location of cp_pos and trim left or right legs of event
if cp_pos < myEvents(k,2)-myEvents(k,1)+1
    myEvents(k,1) = myEvents(k,1) + cp_pos - 1;
else
    myEvents(k,3) = myEvents(k,1) + cp_pos - 1;
end

assignin('base','myEvents',myEvents); %update in base workspace

%Update axes1
y2 = evalin('base','y2'); %load filtered signal
myEvents = evalin('base','myEvents'); %load myEvents
myEventsFlag = evalin('base','myEventsFlag'); %load myEvents

si = evalin('base','si'); %load sample interval from base workspace


% resample curve and plot resampled curve, use myresample_simple
[yRis yDec yRes siNew] = myResample_simple_extend(y2,myEvents(k,1),myEvents(k,3),si,(si/0.0001));

Eventplot = y2(myEvents(k,1):myEvents(k,3));
% Eventplot = y2(myEvents(k,1):myEvents(k,3)); %get event to be plotted
mintemp = min(Eventplot);
Eventplot = Eventplot - mintemp; %translate signal to origin
mintemp = min(yRis);
yRis = yRis - mintemp;
mintemp = min(yDec);
yDec = yDec - mintemp;

% Generate time series x-axis
xR = (1:length(yRis))*siNew; %get x-vector in time units
xD = (1:length(yDec))*siNew; %get x-vector in time units
xRD = (1:length(Eventplot))*si; %get x-vector in time units

% Plot data
handles.axes1_plot1 = plot(handles.axes1,xRD,Eventplot,'k.'); %plot in axes1
handles.axes2_plot1 = plot(handles.axes2,xR,yRis,'k.'); %plot rising leg in axes2
handles.axes3_plot1 = plot(handles.axes3,xD,yDec,'k.'); %plot rising leg in axes2

% Axes eassign the callback to axes buttondownFcn b/c when you plot on an axes that has the nextplot property set to replace, all callbacks, etc are reset in that call
axes1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
set(handles.axes1,'ButtonDownFcn',axes1_buttonDownFcn_String); %set buttondown callback

% Plot1 assign callback to buttondownFcn
axes1_plot1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
set(handles.axes1_plot1,'ButtonDownFcn',axes1_plot1_buttonDownFcn_String); %set buttondown callback

% Activate pointer manager
iptPointerManager(handles.figure1);

% Change cursor object when in axes1
%     axes1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_pointer_Fcn',hObject,eventdata,guidata(hObject));
iptSetPointerBehavior(handles.axes1, @axes1_pointer_Fcn)

% Change cursor object when in object1
%     axes1_plot1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_pointer_Fcn',hObject,eventdata,guidata(hObject));
iptSetPointerBehavior(handles.axes1_plot1, @axes1_plot1_pointer_Fcn)

% disp('Clicked Axes')
% disp(['Nearest point ', num2str(cp_pos)])

% Count good Events up to any point in array
cgE = ~myEventsFlag(1:k); %take the logical opposite up to slider position
cbE = length(cgE); cgE = sum(cgE); %count events,  %sum the logical opposite
% Update display of text1
set(handles.text1,'String',['Event (Good/Total): ',num2str(cgE), ' / ', num2str(cbE)])
%///////////////////////////////////////////////


%```````````````````````````````````````````````

FIT CURVES

back to top
Oops...

Oops...

Oops...

Oops...

Oops...

Oops...

Oops...
%```````````````````````````````````````````````
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%
slider1pos = round(get(handles.slider1,'Value')); %get slider position

% Get variables for updating axes
y2 = evalin('base','y2'); %load filtered signal
myEvents = evalin('base','myEvents'); %load myEvents
myEventsFlag = evalin('base','myEventsFlag'); %load myEventsFlag

k = slider1pos;
si = evalin('base','si'); %load sample interval from base workspace


if myEventsFlag(k) == 1
    return;
else
    % Activate pointer manager
    iptPointerManager(handles.figure1);
    % Show busy pointer
    set(handles.figure1,'Pointer','watch');
    pause(0.1); %update plots

    Eventplot = y2(myEvents(k,1):myEvents(k,3));
    % Eventplot = y2(myEvents(k,1):myEvents(k,3)); %get event to be plotted
    mintemp = min(Eventplot);
    Eventplot = Eventplot - mintemp; %translate signal to origin

    % resample curve and plot resampled curve, use myresample_simple
    [yRis yDec yRes siNew] = myResample_simple_extend(y2,myEvents(k,1),myEvents(k,3),si,(si/0.0001));
    mintemp = min(yRis);
    yRis = yRis - mintemp;
    mintemp = min(yDec);
    yDec = yDec - mintemp;

    % Generate time series x-axis
    xR = (1:length(yRis))*siNew; %get x-vector in time units
    xD = (1:length(yDec))*siNew; %get x-vector in time units
    xRD = (1:length(Eventplot))*si; %get x-vector in time units

    % Compute best fit
    [yR_fit_obj yR_stat] = myfity2(yRis,'n',siNew,'');
    [yD_fit_obj yD_stat] = myfity1(yDec,'n',siNew,'');
    % Get fit parameters
    yR_alpha = yR_fit_obj.alpha;
    yR_beta = yR_fit_obj.beta;
    yD_alpha = yD_fit_obj.alpha;
    yD_beta = yD_fit_obj.beta;
    % Generate fit curve
    yR_fit = yR_alpha*(1-exp(-yR_beta*(xR)));
    yD_fit = yD_alpha*(exp(-yD_beta*(xD)));

    % Plot Data
    handles.axes1_plot1 = plot(handles.axes1,xRD,Eventplot,'k.'); %plot in axes1
    handles.axes2_plot1 = plot(handles.axes2,xR,yRis,'k.'); %plot rising leg in axes2
    handles.axes3_plot1 = plot(handles.axes3,xD,yDec,'k.'); %plot rising leg in axes2
    % Plot fits
    hold(handles.axes2,'on'); %plot rising leg in axes2
    plot(handles.axes2,xR,yR_fit,'b','LineWidth',3); hold(handles.axes2,'off'); %plot rising fit in axes2
    hold(handles.axes3,'on'); %plot rising leg in axes2
    plot(handles.axes3,xD,yD_fit,'b','LineWidth',3); hold(handles.axes3,'off'); %plot decay fit in axes2

    % Axes eassign the callback to axes buttondownFcn b/c when you plot on an axes that has the nextplot property set to replace, all callbacks, etc are reset in that call
    axes1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
    set(handles.axes1,'ButtonDownFcn',axes1_buttonDownFcn_String); %set buttondown callback

    % Plot1 assign callback to buttondownFcn
    axes1_plot1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
    set(handles.axes1_plot1,'ButtonDownFcn',axes1_plot1_buttonDownFcn_String); %set buttondown callback

    % Change cursor object when in axes1
%     axes1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_pointer_Fcn',hObject,eventdata,guidata(hObject));
    iptSetPointerBehavior(handles.axes1, @axes1_pointer_Fcn)

    % Change cursor object when in object1
%     axes1_plot1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_pointer_Fcn',hObject,eventdata,guidata(hObject));
    iptSetPointerBehavior(handles.axes1_plot1, @axes1_plot1_pointer_Fcn)

    % Get the axes and figure positions in pixesl units
    axes_Units = get(handles.axes1,'Units'); %get the current units
    set(handles.axes1,'Units','Pixels') %when left as pixels, scaling does not work
    axes_pos = get(handles.axes1,'Position'); %get position in pixels
    set(handles.axes1,'Units',axes_Units); %set back to original state

    Fig1_Units = get(handles.figure1,'Units'); %get the current units
    set(handles.figure1,'Units','Pixels') %when left as pixels, scaling does not work
    Fig1_pos = get(handles.figure1,'Position'); %get position in pixels
    set(handles.figure1,'Units',Fig1_Units); %set back to original state

    cp = get(0,'PointerLocation');
    cp = cp-Fig1_pos(1:2)+1;

    % Determin if cursor is in axes 1
    if axes_pos(1) <= cp(1) && cp(1) <= axes_pos(1) + axes_pos(3) && ...
        axes_pos(2) <= cp(2) && cp(2) <= axes_pos(2) + axes_pos(4)
        % Show full crosshair
        set(handles.figure1,'Pointer','fullcrosshair');
    else
        % Show normal pointer
        set(handles.figure1,'Pointer','arrow');
    end

end
%///////////////////////////////////////////////


%```````````````````````````````````````````````

KEYBOARD INPUT

back to top
%```````````````````````````````````````````````
% --- Executes on key release with focus on figure1 or any of its controls.
function figure1_WindowKeyReleaseFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  structure with the following fields (see FIGURE)
%	Key: name of the key that was released, in lower case
%	Character: character interpretation of the key(s) that was released
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) released
% handles    structure with handles and user data (see GUIDATA)
%

% Get eventdata
rk = eventdata.Key;
rm = eventdata.Modifier;

% get gui handles structure
data = guidata(hObject);

% Create switch block
switch rk

    case 'q'
        % open folder
        hgfeval({@pushbutton1_Callback,[],[],data});
    case 'e'
        % open file
        hgfeval({@pushbutton2_Callback,[],[],data});
    case 'c'
        % fit curves
        hgfeval({@pushbutton6_Callback,[],[],data});
    case 'f'
        % flag
        hgfeval({@pushbutton4_Callback,[],[],data});
    case 'g'
        % unflag
        hgfeval({@pushbutton5_Callback,[],[],data});
    case 'a'
        % move slider left
        s_min = round(get(handles.slider1,'Min'));
        s_cp = round(get(handles.slider1,'Value'));

        if s_cp > s_min
            set(handles.slider1,'Value',s_cp-1)
            hgfeval({@slider1_Callback,[],[],data});
        end

    case 'd'
        % move slider right
        s_max = round(get(handles.slider1,'Max'));
        s_cp = round(get(handles.slider1,'Value'));

        if s_cp < s_max
            set(handles.slider1,'Value',s_cp+1)
            hgfeval({@slider1_Callback,[],[],data});
        end

    case 's'
        % check for midifier
        if strcmp(rm,'shift')
            %save
            hgfeval({@pushbutton3_Callback,[],[],data});
        end

    case 'r'
        % check for midifier
        if strcmp(rm,'shift')
            %reset
            hgfeval({@pushbutton7_Callback,[],[],data});
        end

    otherwise; return

end
%///////////////////////////////////////////////


%```````````````````````````````````````````````

RESET

back to top
%```````````````````````````````````````````````
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%
% Activate pointer manager
iptPointerManager(handles.figure1);
% Show busy pointer
set(handles.figure1,'Pointer','watch');
pause(0.1); %update plots

% Get event number
slider1pos = round(get(handles.slider1,'Value')); %get slider position
k = slider1pos;

% Reload Event from copy
myEvents = evalin('base','myEvents');
myEvents_copy = evalin('base','myEvents_copy');
myEvents(k,:) = myEvents_copy(k,:);
assignin('base','myEvents',myEvents);

myEventsFlag = evalin('base','myEventsFlag');

%Update axes1
y2 = evalin('base','y2'); %load filtered signal
si = evalin('base','si'); %load sample interval from base workspace


% resample curve and plot resampled curve, use myresample_simple
[yRis yDec yRes siNew] = myResample_simple_extend(y2,myEvents(k,1),myEvents(k,3),si,(si/0.0001));

Eventplot = y2(myEvents(k,1):myEvents(k,3));
% Eventplot = y2(myEvents(k,1):myEvents(k,3)); %get event to be plotted
mintemp = min(Eventplot);
Eventplot = Eventplot - mintemp; %translate signal to origin
mintemp = min(yRis);
yRis = yRis - mintemp;
mintemp = min(yDec);
yDec = yDec - mintemp;

% Generate time series x-axis
xR = (1:length(yRis))*siNew; %get x-vector in time units
xD = (1:length(yDec))*siNew; %get x-vector in time units
xRD = (1:length(Eventplot))*si; %get x-vector in time units

% Plot Data
handles.axes1_plot1 = plot(handles.axes1,xRD,Eventplot,'k.'); %plot in axes1
handles.axes2_plot1 = plot(handles.axes2,xR,yRis,'k.'); %plot rising leg in axes2
handles.axes3_plot1 = plot(handles.axes3,xD,yDec,'k.'); %plot rising leg in axes2

% Axes assign the callback to axes buttondownFcn b/c when you plot on an axes that has the nextplot property set to replace, all callbacks, etc are reset in that call
axes1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
set(handles.axes1,'ButtonDownFcn',axes1_buttonDownFcn_String); %set buttondown callback

% Plot1 assign callback to buttondownFcn
axes1_plot1_buttonDownFcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_ButtonDownFcn',hObject,eventdata,guidata(hObject));
set(handles.axes1_plot1,'ButtonDownFcn',axes1_plot1_buttonDownFcn_String); %set buttondown callback

% Activate pointer manager
iptPointerManager(handles.figure1);

% Change cursor object when in axes1
axes1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_pointer_Fcn',hObject,eventdata,guidata(hObject));
iptSetPointerBehavior(handles.axes1, axes1_pointer_Fcn_String)

% Change cursor object when in object1
axes1_plot1_pointer_Fcn_String = @(hObject,eventdata)EditEvents('axes1_plot1_pointer_Fcn',hObject,eventdata,guidata(hObject));
iptSetPointerBehavior(handles.axes1_plot1, axes1_plot1_pointer_Fcn_String)

% Get the axes and figure positions in pixesl units
axes_Units = get(handles.axes1,'Units'); %get the current units
set(handles.axes1,'Units','Pixels') %when left as pixels, scaling does not work
axes_pos = get(handles.axes1,'Position'); %get position in pixels
set(handles.axes1,'Units',axes_Units); %set back to original state

Fig1_Units = get(handles.figure1,'Units'); %get the current units
set(handles.figure1,'Units','Pixels') %when left as pixels, scaling does not work
Fig1_pos = get(handles.figure1,'Position'); %get position in pixels
set(handles.figure1,'Units',Fig1_Units); %set back to original state

cp = get(0,'PointerLocation');
cp = cp-Fig1_pos(1:2)+1;

% Determin if cursor is in axes 1
if axes_pos(1) <= cp(1) && cp(1) <= axes_pos(1) + axes_pos(3) && ...
    axes_pos(2) <= cp(2) && cp(2) <= axes_pos(2) + axes_pos(4)
    % Show full crosshair
    set(handles.figure1,'Pointer','fullcrosshair');
else
    % Show normal pointer
    set(handles.figure1,'Pointer','arrow');
end
%///////////////////////////////////////////////


% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


%```````````````````````````````````````````````

MAKE PLOT

back to top
Oops...

Oops...

Oops...

Oops...
%```````````````````````````````````````````````
% --------------------------------------------------------------------
function makePlot_ClickedCallback(hObject, eventdata, handles)
% hObject    handle to makePlot (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get event number
slider1pos = round(get(handles.slider1,'Value')); %get slider position

% Get variables for updating axes
y2 = evalin('base','y2'); %load filtered signal
myEvents = evalin('base','myEvents'); %load myEvents
myEventsFlag = evalin('base','myEventsFlag'); %load myEventsFlag

k = slider1pos;
si = evalin('base','si'); %load sample interval from base workspace


if myEventsFlag(k) == 1
    return;
else

    % Get variables
    Eventplot = y2(myEvents(k,1):myEvents(k,3));
    % Eventplot = y2(myEvents(k,1):myEvents(k,3)); %get event to be plotted
    mintemp = min(Eventplot);
    Eventplot = Eventplot - mintemp; %translate signal to origin

    % resample curve and plot resampled curve, use myresample_simple
    [yRis yDec yRes siNew] = myResample_simple_extend(y2,myEvents(k,1),myEvents(k,3),si,(si/0.0001));
    mintemp = min(yRis);
    yRis = yRis - mintemp;
    mintemp = min(yDec);
    yDec = yDec - mintemp;

    % Generate time series x-axis
    xR = (1:length(yRis))*siNew; %get x-vector in time units
    xD = (1:length(yDec))*siNew; %get x-vector in time units
    xRD = (1:length(Eventplot))*si; %get x-vector in time units

    % Compute best fit
    [yR_fit_obj yR_stat] = myfity2(yRis,'n',siNew,'');
    [yD_fit_obj yD_stat] = myfity1(yDec,'n',siNew,'');
    % Get fit parameters
    yR_alpha = yR_fit_obj.alpha;
    yR_beta = yR_fit_obj.beta;
    yD_alpha = yD_fit_obj.alpha;
    yD_beta = yD_fit_obj.beta;
    % Generate fit curve
    yR_fit = yR_alpha*(1-exp(-yR_beta*(xR)));
    yD_fit = yD_alpha*(exp(-yD_beta*(xD)));


    % Get save location
    % Select Folder
    mydircheck = evalin('base','exist(''mydirSave'',''var'');');
    if mydircheck == 0
        mydirChoose = pwd;
    else
        mydirChoose = evalin('base','mydirSave'); %get previously selected path
    end

    % Get folder path
    mydirChoose = uigetdir(mydirChoose); %get path to chosen directory

    % if no folder selected return to gui
    if mydirChoose == 0
        msgbox('Select a folder')
        return;
    end

    % Save mydirChoose to workspace
    assignin('base','mydirSave',mydirChoose); %save variable to workspace

    % Get File name
    Eventsfile = evalin('base','Eventsfile');
    fileName =  regexprep(Eventsfile, '_autoEventStats.mat', '');

    % Check file path for MEP, MEPPs or EPC, EPCs
    analysisfilePath = evalin('base','mydirChoose'); %get file path for analysis file
    recordType = regexp(analysisfilePath, '(MEP|MEPPs|EPC|EPCs)', 'match');
    recordType = char(recordType);

    % Determine Units based on record type
    if strcmp(recordType, 'MEP') || strcmp(recordType, 'MEPPs')
        unitsY = 'mV';
    else
        unitsY = 'nA';
    end

    % Check abf file for gain value
    abfFile = [fileName, '.abf'];
    %Search the file for the Gain information
    myfileN = abfFile; %enter file name
    fid = fopen(myfileN,'r','ieee-le'); %open the abf file, readonly, machine format
    sz=1;  %# of data entries to read
    numType = 'float'; %precision format
    myGainfileoffset = 268; %find the correct offset where data entry for gain begins
    fseek(fid,myGainfileoffset,'bof'); %move field position
    cellGain = fread(fid,sz,numType); %read formatted data
    fclose(fid); %close file

    % Correct Y data by Gain value
    Eventplot = Eventplot/cellGain;
    yRis = yRis/cellGain;
    yR_fit = yR_fit/cellGain;
    yDec = yDec/cellGain;
    yD_fit = yD_fit/cellGain;

    % Plot Data
    hf_curve = figure; ha_curve = axes; plot(xRD,Eventplot,'k','LineWidth',10,'MarkerSize',15); set(gca,'Box','off'); %plot in axes1
    hf_yRis = figure; ha_yRis = axes; plot(xR,yRis,'k','LineWidth', 10,'MarkerSize',15); set(gca,'Box','off');%plot rising leg in axes2
    hf_yDec = figure; ha_yDec = axes; plot(xD,yDec,'k','LineWidth', 10,'MarkerSize',15); set(gca,'Box','off');%plot rising leg in axes2

    % Plot fits
    hold(ha_yRis,'on'); %plot rising leg in axes2
    plot(ha_yRis,xR,yR_fit,'b','LineWidth',3); hold(ha_yRis,'off'); %plot rising fit in axes2
    hold(ha_yDec,'on'); %plot rising leg in axes2
    plot(ha_yDec,xD,yD_fit,'b','LineWidth',3); hold(ha_yDec,'off'); %plot decay fit in axes2

    % Count good Events up to any point in array
    cgE = ~myEventsFlag(1:k); %take the logical opposite up to slider position
    cgE = sum(cgE); %count events,  %sum the logical opposite
    Event = num2str(cgE);

    % Modify fileName for printing
    fileNamePrint = regexprep(fileName,'_','\\_');

    % Save Plots
    % Curve
    AxisFont = 18;
    figure(hf_curve)
    gcf; title({[recordType, ' ', fileNamePrint, '\_', 'Event\_', Event]},'FontSize',AxisFont);
    saveas(gcf,[mydirChoose, '\', recordType, '_', fileName, '_', Event, '.pdf'], 'pdf');
    close gcf;

    % Rising curve
    figure(hf_yRis)
    gcf; title({[recordType, ' ', fileNamePrint, '\_', 'Event\_', Event, ' Rising']},'FontSize',AxisFont);
    % Format plot
    legend('Data', 'Fit Curve','Location','SouthEast') %place legend
    xlabel('Time(seconds)','FontSize',20) %x-axis label
    ylabel(['Amplitude (', unitsY, ')'], 'FontSize',20) %y-axis label
    xpos = get(ha_yRis,'XLim');
    ypos = get(ha_yRis,'Ylim');
    % Make strings of equations using tex syntax
    strn1 = '$y={\alpha}\left(1-\exp({-\beta}{x})\right)$';
    strn2 = sprintf('$y={%0.4f}\\left(1-\\exp({-%0.g}{x})\\right)$',yR_fit_obj.alpha, yR_fit_obj.beta);
    strn3 = sprintf('$R^2={%0.4f}$',abs(yR_stat.rsquare));
    strn4 = sprintf('$\\beta=\\frac{1}{\\tau}={%0.4g}\\left( seconds \\right)$',(1/yR_fit_obj.beta));
    % Enter fit parameters plotting w.r.t. origin
    text('Interpreter','latex','string',...
    {strn1;strn2;strn3;strn4},...
    'Position',[xpos(2),0.5*ypos(2)],...
    'HorizontalAlignment','Right','VerticalAlignment','Middle','FontSize',16)
    % Save plot
    saveas(gcf,[mydirChoose, '\', recordType, '_', fileName, '_', Event, '_Rise', '.pdf'], 'pdf');
    close gcf;

    % Decay curve
    figure(hf_yDec)

    gcf; title({[recordType, ' ', fileNamePrint, '\_', 'Event\_', Event, ' Decay']},'FontSize',AxisFont);
    % Format plot
    legend('Data', 'Fit Curve','Location','SouthWest') %place legend
    xlabel('Time(seconds)','FontSize',20) %x-axis label
    ylabel(['Amplitude (', unitsY, ')'], 'FontSize',20) %y-axis label
    xpos = get(ha_yDec,'XLim');
    ypos = get(ha_yDec,'Ylim');
    % Make strings of equations using tex syntax
    strn1 = '$y={\alpha}\left(1-\exp({-\beta}{x})\right)$';
    strn2 = sprintf('$y={%0.4f}\\left(1-\\exp({-%0.g}{x})\\right)$',yD_fit_obj.alpha, yD_fit_obj.beta);
    strn3 = sprintf('$R^2={%0.4f}$',abs(yD_stat.rsquare));
    strn4 = sprintf('$\\beta=\\frac{1}{\\tau}={%0.4g}\\left( seconds \\right)$',(1/yD_fit_obj.beta));
    % Enter fit parameters plotting w.r.t. origin
    text('Interpreter','latex','string',...
    {strn1;strn2;strn3;strn4},...
    'Position',[xpos(2),ypos(2)],...
    'HorizontalAlignment','Right','VerticalAlignment','Top','FontSize',16)
    % Save plot
    saveas(gcf,[mydirChoose, '\', recordType, '_', fileName, '_', Event, '_Decay', '.pdf'], 'pdf');
    close gcf;


end
Error using ==> load
Unable to read file EditEvents_publish.fig: No such file or directory.

Error in ==> hgload>localLoadFile at 177
AllVars = load(filename, '-mat');

Error in ==> hgload at 59
[FigVersion, FigData, VerNum] = localLoadFile(filename);

Error in ==> openfig at 72
    [fig, savedvisible] = hgload(filename, struct('Visible','off'));

Error in ==> gui_mainfcn>local_openfig at 286
    gui_hFigure = openfig(name, singleton, visible);

Error in ==> gui_mainfcn at 159
        gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt, gui_Visible);

Error in ==> EditEvents_publish at 44
    gui_mainfcn(gui_State, varargin{:});