Hi, i created a function in matlab that plots a graph giving some inputs. i want to put this function in my GUI and show the graph in the GUI. How can i do that?
At this moment the function runs in the GUI, but the plot it's shown in a figure, not in the UIFigure, how can i fix this problem?
thank you!

 Akzeptierte Antwort

Adam Danz
Adam Danz am 30 Mär. 2021

0 Stimmen

You have to specify the axis handle as the parent of your plotting function. See example.

5 Kommentare

Marco Picillo
Marco Picillo am 31 Mär. 2021
i created the function not in app designer, if i add "app.UIAxes" as first input of the plot in the function, i have an error
Adam Danz
Adam Danz am 31 Mär. 2021
Bearbeitet: Adam Danz am 31 Mär. 2021
It doesn't matter where the function was created. What matters is whether the axes handle is visible. If the axis or figure handlevisibility is set to off then the plotting function will not have access to the axes.
If the axes are not created in app designer I doubt the handle is called "app.UIAxes". Use your axes handle instead of the one in my demo.
If that doesn't solve the problem share the entire error message. Saying there's an error without sharing the entire error message isn't helpful at all.
if I have this function for example, not defined in app designer:
function plotsomething(inp1,inp2,...)
%code for the function
figure(1)
g=fill3(l2.XYZ(:,:,1)',l2.XYZ(:,:,2)',l2.XYZ(:,:,3)','w');
set(g,'LineWidth',2);
view([0,90]);
axis equal,hold on
xlabel(' x-coordinate')
ylabel(' y-coordinate')
zlabel(' z-coordinate')
title(' partition layout')
grid on
h=line([ref.mac_pos(1) ref.mac_pos(1)+ref.C_mac],[ref.mac_pos(2) ref.mac_pos(2)],[ref.mac_pos(3) ref.mac_pos(3)]);
if i want to display this in app designer, so I update the code of the function:
function plotsomething(inp1,inp2,...)
% figure(1) I suppress the figure
fill3(app.UIAxes,l2.XYZ(:,:,1)',l2.XYZ(:,:,2)',l2.XYZ(:,:,3)','w');
set(app.UIAxes,'LineWidth',2);
view(app.UIAxes,[0,90]);
axis equal,hold on
xlabel(app.UIAxes,'x-coordinate')
ylabel(app.UIAxes,'y-coordinate')
zlabel(app.UIAxes,'z-coordinate')
title(app.UIAxes,'partition layout')
grid on
h=line(app.UIAxes,[ref.mac_pos(1) ref.mac_pos(1)+ref.C_mac],[ref.mac_pos(2) ref.mac_pos(2)],[ref.mac_pos(3) ref.mac_pos(3)]);
is this what you mean? thank you!
I see that this is a plotting function.
It is good practice to include a parent handle in the inputs of plotting functions so that all internal plotting commands can act on the specified axes/figure/etc.
For example,
function plotsomething(inp1,inp2,axisHandle)
fill3(axisHandle, . . .)
set(axisHandle, . . .);
view(axisHandle, . . .);
axis(axisHandle, 'equal');
hold(axisHandle, on)
xlabel(axisHandle,'x-coordinate')
% etc....
end
Then call the function from your app using,
plotsomething(x,y,app.UIAxes) % except use YOUR axis handle!
Marco Picillo
Marco Picillo am 31 Mär. 2021
thank you so much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by