matlabmatlab-guidematlab-app-designer

Matlab App Designer Callback function keeps resetting plot with a double click to position it is first set at


I recently converted an app originally designed in GUIDE into App Designer. I did not write the original code, and due to the conversion I'm at a bit of a loss on how to even search for an answer to this question. I apologize if this has been covered elsewhere.

In my app, I can load txt files which contain signal data on a linear time scale. Using the app, I can scroll to a signal of interest. I then set the 'origo', or the origin of the signal with a Callback function, which replots the signal over a consistent timescale.

This works exactly like the old tool did, which is great. I can process the signal, and move on. The issue is when I zoom out, and then scroll to find my next signal of interest. If I at all double click anywhere on the plot, the plot zooms once again to the origo position with a consistent timescale created by the setorigo_Callback function. Additionally, if I find other signals of interested and process them, including a setting a new origo location on the x-axis, if I double click at all it will zoom to the first origo position I specified. It doesn't matter if I've set a new origo, the double click will send me to the location of the first origo process when I first opened the app.

Anyone have any idea what's going on here? Or furthermore, how I can stop it? I can't seem to clear the origo valuable, or wipe the plot's memory of the first origo set. Please see full code. Many thanks!

Sample data: 1990.txt

Minute  microsec    cycles  SPL_Pa  kHz Bandwidth   end kHz
14/5/2019 13:11 3220245 6   97  149 2   185
14/5/2019 13:11 4479150 11  16  55  5   83
14/5/2019 13:11 4479650 4   54  61  0   64
... and so on.

classdef cpodcalibrate_App < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        figure1           matlab.ui.Figure
        Untitled_1        matlab.ui.container.Menu
        loaddata          matlab.ui.container.Menu
        loadmatdata       matlab.ui.container.Menu
        savedata          matlab.ui.container.Menu
        uitoolbar1        matlab.ui.container.Toolbar
        uitoggletool1     matlab.ui.container.toolbar.ToggleTool
        uitoggletool2     matlab.ui.container.toolbar.ToggleTool
        uitoggletool3     matlab.ui.container.toolbar.ToggleTool
        removeechoes      matlab.ui.control.Button
        Addtotable        matlab.ui.control.Button
        podnumber         matlab.ui.control.EditField
        datatable         matlab.ui.control.Table
        Frequencyselect   matlab.ui.control.ListBox
        angleselect       matlab.ui.control.ListBox
        removefromtable   matlab.ui.control.Button
        setorigo          matlab.ui.control.Button
        divisionline      matlab.ui.control.Button
        edit2             matlab.ui.control.EditField
        clickplot         matlab.ui.control.UIAxes
        thresholdplot     matlab.ui.control.UIAxes
        nixplot           matlab.ui.control.UIAxes
    end

    
    methods (Access = private)
        function updateplot(app, handles)
            
            global data t
            axes(handles.clickplot);
            cla;
            t=((data.datetime(:,4)*60+data.datetime(:,5))-(data.datetime(1,4)*60-data.datetime(1,5)))*60+data.rectime*1e-6;
            plot(t,log10(data.nix),'.')
        end
        
        function resetInteractions(app, event)
            % This function resets the states of the toggle tools that
            % impact user interactions.  It also resets the figure interactions.
             
            % Find all tools to reset.  Exclude the tool associated
            % with the event.
            interactiveTools = [app.uitoggletool1, app.uitoggletool2, app.uitoggletool3];
            interactiveTools(event.Source == interactiveTools) = [];
             
            % Set the state of the tools to 'off'.
            [interactiveTools.State] = deal('off');
             
            % Set figure interactions to 'off'.
            datacursormode(app.figure1, 'off')
            rotate3d(app.figure1, 'off');
            pan(app.figure1, 'off');
            zoom(app.figure1,'off');
        end
        
        % Update components that require runtime configuration
        function addRuntimeConfigurations(app)
            
            % Set component properties that require runtime configuration
            app.datatable.BackgroundColor = [1 1 1;0.9608 0.9608 0.9608];
            app.datatable.ColumnFormat = {[] [] [] [] [] [] [] [] []};
        end
    end
    

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function cpodcalibrate_OpeningFcn(app, varargin)
            % Add runtime required configuration - Added by Migration Tool
            addRuntimeConfigurations(app);
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app); %#ok<ASGLU>
            
            % 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 cpodcalibrate (see VARARGIN)
            
            % Choose default command line output for cpodcalibrate
            handles.output = hObject;
            
            % Update handles structure
            guidata(hObject, handles);
        end

        % Button pushed function: Addtotable
        function Addtotable_Callback(app, event)
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            %add line to table
            
            global threshold
            
            axes(handles.nixplot)
            regline=lsline;
            for angle=1:4
                y=get(regline(angle),'Ydata');
                sensitivity(angle)=y(1);
            end;
            %keyboard
            
            datastring=cell(1,9);
            datastring(1)=num2cell(str2double(get(handles.podnumber,'string')));
            for n=1:4
                datastring(1+n)=num2cell(sensitivity(n));
                datastring(5+n)=num2cell(threshold(n));
            end
            table=get(handles.datatable,'data');
            %keyboard;
            if size(table,1)==0
                table=datastring;
            else
                table=[table;datastring];
            end
            set(handles.datatable,'data',table);
            save('Calibration.mat','table');
        end

        % Button pushed function: divisionline
        function divisionline_Callback(app, event)
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            % hObject    handle to divisionline (see GCBO)
            % eventdata  reserved - to be defined in a future version of MATLAB
            % handles    structure with handles and user data (see GUIDATA)
            
            global divider
            axes(handles.clickplot)
            divider=gline;
        end

        % Menu selected function: loaddata
        function loaddata_Callback(app, event)
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            %Load C-POD export data
            
            global data clicks meannix newfilename
            [filename, pathname] = uigetfile('*.txt');
            
            raw=readtable([pathname filename]);
            %If there is an extra column on the older text files, this will
            %sort the columnns correctly.
            if width(raw)>7
                rr=1;
            else
                rr=0;
            end
            headers = raw.Properties.VariableNames;


            %% Extract variables from file content
            
            %Removes last line in data, as often incomplete.
            raw(end,:)=[];
            data.datetime=datevec(datetime(raw.(1)));
            set(handles.podnumber,'string',filename(1:4));
            data.podid=str2double(filename(1:4));
            data.recdate=char(raw.(1));
            data.rectime=raw.(2+rr); %useconds after whole minute
            data.cycles=raw.(3+rr);         % cycles
            data.nix=raw.(4+rr);            % peak pressure, Nick-units
            data.frq=raw.(5+rr);            % Instantaneous frequency
            data.bandwidth=raw.(6+rr);      % Bandwidth, Nick-unit
            data.endfrq=raw.(7+rr);        % End-frequency in sweep

            newfilename=[filename(1:end-4), '.mat'];
            %keyboard
            save(newfilename,'data');
            updateplot(app, handles);
            %initiate results arrays and clear plots
            clicks=zeros(31,4); %number of clicks detected
            meannix=zeros(31,4); %mean nix per block of 10 clicks
            axes(handles.thresholdplot);
            axes(handles.nixplot);
        end

        % Button pushed function: removeechoes
        function removeechoes_Callback(app, event)
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            %Insert line and remove echoes
            
            global data t origo clicks meannix divider threshold newfilename
            axes(handles.clickplot)
            x=get(divider,'Xdata');
            y=get(divider,'Ydata');
            alpha=(y(1)-y(2))/(x(1)-x(2));
            beta=y(1)-alpha*x(1);
            xlim=get(handles.clickplot,'xlim');
            clicksinplotx=t(t>xlim(1)&t<xlim(2));
            clicksinploty=data.nix(t>xlim(1)&t<xlim(2));
            divideline=(clicksinplotx)*alpha+beta;
            hold on
            plot(clicksinplotx,divideline)
            selectedclicksx=clicksinplotx(log10(clicksinploty)>divideline)-origo;
            selectedclicksy=clicksinploty(log10(clicksinploty)>divideline);
            %plot and analyze
            angle=get(handles.angleselect,'value');
            breaks=(0.0485:0.012:0.425)'; %Create breaks to separate blocks
            for n=1:31
                clicks(n,angle)=sum(selectedclicksx>breaks(n)&selectedclicksx<breaks(n+1));
                meannix(n,angle)=mean(selectedclicksy(selectedclicksx>breaks(n)&selectedclicksx<breaks(n+1)));
            end
            axes(handles.thresholdplot);
            att=0:30;
            plot(att,clicks,'o-')
            above=att(clicks(:,angle)>=5);
            below=att(clicks(:,angle)<5);
            %keyboard
            if isempty(above)   %all levels below threshold
                threshold(angle)=NaN;
            else
                threshold(angle)=(above(end)+below(1))/2;
            end
            legend('0','90','180','270');
            axes(handles.nixplot)
            plot(att,20*log10(meannix),'.')
            legend('0','90','180','270');
            save(newfilename,'clicks','meannix','-append')
        end

        % Menu selected function: savedata
        function savedata_Callback(app, event)
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            % Save spreadsheet to excelfile
            
            table=get(handles.datatable,'data');
            xlswrite('Calibration.xls',table);
            save('Calibraton.mat','table');
        end

        % Button pushed function: setorigo
        function setorigo_Callback(app, event)
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            % set t-axis zero at first sync pulse
            
            global origo t data
            axes(handles.clickplot)
            [origo,y]=ginput(1);
            cla;
            plot(t,log10(data.nix),'.');
            %Origo for click file without calib tones
            %set(handles.clickplot,'xlim',[origo origo+0.425],'xtick',[origo+0.0005:0.012:origo+0.425]','xgrid','on');
            set(handles.clickplot,'xlim',[origo origo+0.425],'xtick',[origo+0.0485:0.012:origo+0.425]','xgrid','on');
            hold on
            plot(origo,y,'or');
        end

       
        % Clicked callback: uitoggletool3
        function uitoggletool3_ClickedCallback(app, event)
            % Reset the states of interactive tools and reset all figure
            % interactions.
            app.resetInteractions(event);
             
            % Enable or disable pan based on the
            % tool's current state.
            state = app.uitoggletool3.State;
            pan(app.figure1, char(state));
        end

        % Clicked callback: uitoggletool2
        function uitoggletool2_ClickedCallback(app, event)
            % Reset the states of interactive tools and reset all figure
            % interactions.
            app.resetInteractions(event);
             
            % Enable or disable zoom-out based on the
            % tool's current state.
            state = app.uitoggletool2.State;
            zoomModeObject = zoom(app.figure1);
            if state
                zoomModeObject.Direction = 'out';
                zoomModeObject.Enable = 'on';
            else
                zoomModeObject.Enable = 'off';
            end
        end

        % Clicked callback: uitoggletool1
        function uitoggletool1_ClickedCallback(app, event)
            % Reset the states of interactive tools and reset all figure
            % interactions.
            app.resetInteractions(event);
             
            % Enable or disable zoom-in based on the
            % tool's current state.
            state = app.uitoggletool1.State;
            zoomModeObject = zoom(app.figure1);
            if state
                zoomModeObject.Direction = 'in';
                zoomModeObject.Enable = 'on';
            else
                zoomModeObject.Enable = 'off';
            end
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create figure1 and hide until all components are created
            app.figure1 = uifigure('Visible', 'off');
            app.figure1.Colormap = [0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0];
            app.figure1.Position = [520 157 1142 644];
            app.figure1.Name = 'cpodcalibrate';
            app.figure1.Resize = 'off';
            app.figure1.HandleVisibility = 'on';
            app.figure1.Tag = 'figure1';

            % Create Untitled_1
            app.Untitled_1 = uimenu(app.figure1);
            app.Untitled_1.Text = 'File';
            app.Untitled_1.Tag = 'Untitled_1';

            % Create loaddata
            app.loaddata = uimenu(app.Untitled_1);
            app.loaddata.MenuSelectedFcn = createCallbackFcn(app, @loaddata_Callback, true);
            app.loaddata.Text = 'Open CPOD file';
            app.loaddata.Tag = 'loaddata';

            % Create loadmatdata
            app.loadmatdata = uimenu(app.Untitled_1);
            app.loadmatdata.Text = 'Open mat-file';
            app.loadmatdata.Tag = 'loadmatdata';

            % Create savedata
            app.savedata = uimenu(app.Untitled_1);
            app.savedata.MenuSelectedFcn = createCallbackFcn(app, @savedata_Callback, true);
            app.savedata.Text = 'save';
            app.savedata.Tag = 'savedata';

            % Create uitoolbar1
            app.uitoolbar1 = uitoolbar(app.figure1);
            app.uitoolbar1.Tag = 'uitoolbar1';

            % Create uitoggletool1
            app.uitoggletool1 = uitoggletool(app.uitoolbar1);
            app.uitoggletool1.Tag = 'uitoggletool1';
            app.uitoggletool1.Tooltip = 'Zoom In';
            app.uitoggletool1.ClickedCallback = createCallbackFcn(app, @uitoggletool1_ClickedCallback, true);
            app.uitoggletool1.Icon = 'uitoggletool1_image.png';

            % Create uitoggletool2
            app.uitoggletool2 = uitoggletool(app.uitoolbar1);
            app.uitoggletool2.Tag = 'uitoggletool2';
            app.uitoggletool2.Tooltip = 'Zoom Out';
            app.uitoggletool2.ClickedCallback = createCallbackFcn(app, @uitoggletool2_ClickedCallback, true);
            app.uitoggletool2.Icon = 'uitoggletool2_image.png';

            % Create uitoggletool3
            app.uitoggletool3 = uitoggletool(app.uitoolbar1);
            app.uitoggletool3.Tag = 'uitoggletool3';
            app.uitoggletool3.Tooltip = 'Pan';
            app.uitoggletool3.ClickedCallback = createCallbackFcn(app, @uitoggletool3_ClickedCallback, true);
            app.uitoggletool3.Icon = 'uitoggletool3_image.png';

            % Create removeechoes
            app.removeechoes = uibutton(app.figure1, 'push');
            app.removeechoes.ButtonPushedFcn = createCallbackFcn(app, @removeechoes_Callback, true);
            app.removeechoes.Tag = 'removeechoes';
            app.removeechoes.BackgroundColor = [0.925490196078431 0.913725490196078 0.847058823529412];
            app.removeechoes.FontSize = 11;
            app.removeechoes.Position = [250 605 94 22];
            app.removeechoes.Text = 'Remove echoes';

            % Create Addtotable
            app.Addtotable = uibutton(app.figure1, 'push');
            app.Addtotable.ButtonPushedFcn = createCallbackFcn(app, @Addtotable_Callback, true);
            app.Addtotable.Tag = 'Addtotable';
            app.Addtotable.BackgroundColor = [0.925490196078431 0.913725490196078 0.847058823529412];
            app.Addtotable.FontSize = 11;
            app.Addtotable.Position = [970 344 69 22];
            app.Addtotable.Text = 'Add';

            % Create podnumber
            app.podnumber = uieditfield(app.figure1, 'text');
            app.podnumber.Tag = 'podnumber';
            app.podnumber.HorizontalAlignment = 'center';
            app.podnumber.FontSize = 11;
            app.podnumber.Position = [971 394 49 20];
            app.podnumber.Value = '0';

            % Create datatable
            app.datatable = uitable(app.figure1);
            app.datatable.ColumnName = {'POD'; 'Sens 0'; 'Sens 90'; 'Sens 180'; 'Sens 270'; 'Thr 0'; 'Thr 90'; 'Thr 180'; 'Thr 270'};
            app.datatable.ColumnEditable = [false false false false false false false false false];
            app.datatable.Tag = 'datatable';
            app.datatable.FontSize = 11;
            app.datatable.Position = [709 44 422 251];

            % Create Frequencyselect
            app.Frequencyselect = uilistbox(app.figure1);
            app.Frequencyselect.Items = {'110 kHz', '120 kHz', '130 kHz', '140 kHz'};
            app.Frequencyselect.Tag = 'Frequencyselect';
            app.Frequencyselect.FontSize = 11;
            app.Frequencyselect.Position = [970 532 72 62];
            app.Frequencyselect.Value = '130 kHz';

            % Create angleselect
            app.angleselect = uilistbox(app.figure1);
            app.angleselect.Items = {'0 degrees', '90 degrees', '180 degrees', '270 degrees'};
            app.angleselect.Tag = 'angleselect';
            app.angleselect.FontSize = 11;
            app.angleselect.Position = [970 444 89 63];
            app.angleselect.Value = '0 degrees';

            % Create removefromtable
            app.removefromtable = uibutton(app.figure1, 'push');
            app.removefromtable.Tag = 'removefromtable';
            app.removefromtable.BackgroundColor = [0.925490196078431 0.913725490196078 0.847058823529412];
            app.removefromtable.FontSize = 11;
            app.removefromtable.Position = [1051 344 69 22];
            app.removefromtable.Text = 'Remove';

            % Create setorigo
            app.setorigo = uibutton(app.figure1, 'push');
            app.setorigo.ButtonPushedFcn = createCallbackFcn(app, @setorigo_Callback, true);
            app.setorigo.Tag = 'setorigo';
            app.setorigo.BackgroundColor = [0.925490196078431 0.913725490196078 0.847058823529412];
            app.setorigo.FontSize = 11;
            app.setorigo.Position = [50 606 69 22];
            app.setorigo.Text = 'Set origo';

            % Create divisionline
            app.divisionline = uibutton(app.figure1, 'push');
            app.divisionline.ButtonPushedFcn = createCallbackFcn(app, @divisionline_Callback, true);
            app.divisionline.Tag = 'divisionline';
            app.divisionline.BackgroundColor = [0.925490196078431 0.913725490196078 0.847058823529412];
            app.divisionline.FontSize = 11;
            app.divisionline.Position = [150 605 69 22];
            app.divisionline.Text = 'Division Line';

            % Create edit2
            app.edit2 = uieditfield(app.figure1, 'text');
            app.edit2.Tag = 'edit2';
            app.edit2.HorizontalAlignment = 'center';
            app.edit2.FontSize = 11;
            app.edit2.Position = [517 606 89 20];
            app.edit2.Value = 'Edit Text';

         
            % Create clickplot
            app.clickplot = uiaxes(app.figure1);
            app.clickplot.Colormap = [0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0];
            app.clickplot.FontSize = 13;
            app.clickplot.NextPlot = 'replace';
            app.clickplot.Tag = 'clickplot';
            app.clickplot.Position = [24 322 937 280];

            % Create thresholdplot
            app.thresholdplot = uiaxes(app.figure1);
            app.thresholdplot.Colormap = [0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0];
            app.thresholdplot.FontSize = 13;
            app.thresholdplot.NextPlot = 'replace';
            app.thresholdplot.Tag = 'thresholdplot';
            app.thresholdplot.Position = [25 22 336 280];

            % Create nixplot
            app.nixplot = uiaxes(app.figure1);
            app.nixplot.Colormap = [0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0];
            app.nixplot.FontSize = 13;
            app.nixplot.NextPlot = 'replace';
            app.nixplot.Tag = 'nixplot';
            app.nixplot.Position = [375 22 336 280];

            % Show the figure after all components are created
            app.figure1.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = cpodcalibrate_App(varargin)

            runningApp = getRunningApp(app);

            % Check for running singleton app
            if isempty(runningApp)

                % Create UIFigure and components
                createComponents(app)

                % Register the app with App Designer
                registerApp(app, app.figure1)

                % Execute the startup function
                runStartupFcn(app, @(app)cpodcalibrate_OpeningFcn(app, varargin{:}))
            else

                % Focus the running singleton app
                figure(runningApp.figure1)

                app = runningApp;
            end

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.figure1)
        end
    end
end

Solution

  • So taking some advice from @Hoki, I made a new button that resizes the xlims, and other features, of the axes. Now, depending on whether I've last clicked 'set origo' or 'zoom to data', a double click will send me to each range, respectively. This means I can at least get out of the axes limits that set origo determines. I didn't spend the time to get rid of the auto xgrid, because honestly, I can live with it.

    % Button pushed function: ZoomtoDataButton
    function ZoomtoDataButtonPushed(app, event)
        [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
        axes(handles.clickplot)
        cla;
        updateplot(app, handles)
        xlim('auto')
        xticks('auto')
        ylim('auto')
    
    end