This solutions seems to work to maintain the Z-Axis for both the zoom and pan: UIAxes' YLim property cannot be listened to
I added the function to app designer:
function [inclusivezlim] = mapholdaltlims(app,ax)
objwithz = findobj(app.UIAxes.Children,'-property','ZData');
currmin_z = 0;
currmax_z = 0;
for i = 1:length(objwithz)
currmin_z = min([min(min(objwithz(i).ZData)), currmin_z]);%Need double mins because data could be 2d surface
currmax_z = max([max(max(objwithz(i).ZData)), currmax_z]);
end
inclusivezlim = [currmin_z currmax_z];
ax.ZLim = inclusivezlim;
end
And included the following in each of my plot functions:
warning('off','MATLAB:structOnObject');
warning('off','MATLAB:ui:javaframe:PropertyToBeRemoved'); % Added to turn off java warning
addlistener(struct(app.UIAxes).Axes, 'ZLim', 'PostSet', @(src,evnt)mapholdaltlims(app,app.UIAxes));
There is a delay after zooming/panning, when the Z-Axis is replotted, so it's not the fastest solution, but it does works!
Getting lots of warnings that I don't understand either? Does this mean this function will not work in future versions of Matlab?
Warning: The JavaFrame figure property will be removed in a future release. For more information, see
Recommendations for Java and ActiveX Users on mathworks.com.
> In func_name/startupFcn (line 76)
In appdesigner.internal.service/AppManagementService/tryCallback (line 336)
In matlab.apps/AppBase/runStartupFcn (line 41)
In func_name (line 565)
In appdesigner.internal.service/AppManagementService/runAppWithTryCatch (line 161)
In appdesigner.internal.service/AppManagementService/runDesktopApp (line 89)
In appdesigner.internal.model/AppModel/runAppHelper (line 649)
In appdesigner.internal.model.AppModel>@()appdesigner.internal.model.AppModel.runAppHelper(obj,appArguments) (line 509)