I am trying to find a work around to the lack of axes callback usage from within an App Deisnger axes. Ultimately, I want to assign a KeyPressFcn to allow me to manual shift data along the x-axis when pressing left- and right-arrow keys. I am also selectively performing this x-axis shift on only visible lines, were line visibility can be toggled 'on/'off' using the axes legend's ItemHitFcn. Currently, I am copying axes objects to a new figure outside of App Designer were I can acheive this, and can even obtain the new XValues via one of the app's ButtonGUI callbacks, but would much prefer to invoke the button's callback automatically when the figure is closed.
Attempted:
% Figure creation from app
hFig = figure;hAx = axes;hLin = plot(hAx,X,Y);hFig.DeleteFcn = @(app,event) UpdateAxesButtonPushed(app,event,hLin.XData);
Button callback function:
methods (Access = public) function UpdateAxesButtonPushed(app, event, newX) % First verifies that the source of the event is the callback
app.UIAxes.Children(1).XData = newX; end end
Code for an additional attempt is provided code section below in better detail. Also, the error that appears is same for all attempts and is as follows.
Undefined function 'UpdateAxes' for input arguments of type 'matlab.ui.Figure'.
Error using MyApp/UpdateAccPlot (line 221)
Error while evaluating Figure CloseRequestFcn.
methods (Access = public) function UpdateAccPlot(app, event) % Create figure with user defined CloseRequestFcn
hFig = figure('WindowState','maximized','CloseRequestFcn',@UpdateAxes); hAx = axes(hFig); % Plot data
hLin = plot(hAx,app.Data.Time,app.Data.UnfilteredAcc,... app.Data.Time,app.Data.FilteredAcc); hLin(1).Color = [0,0.447,0.741]; hLin(2).Color = [0.929,0.694,0.125]; hold(hAx,'on') plot(hAx,app.Pulse.Time,app.Pulse.Max,'r',... app.Pulse.Time,app.Pulse.Nom,'--k',... app.Pulse.Time,app.Pulse.Min,'r') hold(hAx,'off') hLeg = legend(hAx,{'Unfiltered Data','Filtered Data',... 'Upper Limit','Nominal Pulse','Lower Limit'}); hAx.XLim = app.Pulse.Time([1,end]); % Assign callbacks to new figure plot
app.hGUI = hLin; hLeg.ItemHitFcn = @LineVisible; hFig.KeyPressFcn = @(src,event) LineShift(src,event,hLin); grid on title(hAx,'Shock Pulse Acceleration') xlabel(hAx,'Time (sec)') ylabel(hAx,'Acceleration (g)') waitfor(hFig); app.Data.Time = getappdata(0,'Time'); app.Data.Time = getappdata(0,'Unfiltered'); app.Data.Time = getappdata(0,'Filtered'); end function UpdateAxes(~, ~) hLin = findobj(gcf,'Type','line'); idx{1} = arrayfun(@(a) strcmp(a.DisplayName,'Unfiltered Data'),hLin); idx{2} = arrayfun(@(a) strcmp(a.DisplayName,'Filtered Data'),hLin); setappdata(0,'Time',hLin(idx{1}).XData) setappdata(0,'Unfiltered',hLin(idx{1}).YData) setappdata(0,'Filtered',hLin(idx{2}).YData) closereq endend
Best Answer