MATLAB: How do i embed a mesh plot into appdesigner

MATLABmesh app

I am using the following code and have tried many variants in the hopes of getting the app to own it.
[X,Y] = meshgrid(xlin,ylin);
Z = griddata(x,y,z,X,Y,'cubic');
mesh(X,Y,Z)
axis tight;hold on
When run in a matlab "program" it pops a detached window up that has the figure I want.
I want the image to be within the app (Axis?) generated with app designer. I am running R2020a.

Best Answer

You need to pass the handle of UIaxes to the graphing functions. For example
[X,Y] = meshgrid(xlin,ylin);
Z = griddata(x,y,z,X,Y,'cubic');
mesh(app.UIAxes,X,Y,Z) % UIAxes is the name of your axes object in app designer. Change it according to your app
axis(app.UIAxes, 'tight');
hold(app.UIAxes);
Also see tha attached app for a demo.