How to plot a graph on a panel in App Designer?

Hi.
I have the below app design view, and I would like to plot the same linear graph (y = 1x) on both axes objects, one (UIAxes) is parented to a panel object and the other (UIAxes2) is just on a figure object.
To do this, I have the following callback function startupFcn (executed per app execution).
Then, the execution result is the following; no plot is apprently made on the axes belonging to the panel. Could you tell what was wrong in my code?

1 comentario

Your first diagram makes it look as if the panel is behind an axes. The drawing on top takes priority in App Designer.

Iniciar sesión para comentar.

 Respuesta aceptada

Yukthi S
Yukthi S el 4 de Dic. de 2024
I got that you wanted to plot the same linear graph on two different axes:
a) UIAxes inside a panel and
b) UIAxes2 directly on the figure.
But the function you are using attempts to re-parent UIAxes2 to the panel. The below adjustments to the design and code will achieve the desired behaviour.
  • Make panel the parent component in the design itself.
  • Now switch to Code View and give the below function as the StartupFcn:
function startupFcn(app)
x = 1:1:10; % X data
y = x; % Y data (y = x)
% Plot on UIAxes (inside the Panel)
plot(app.UIAxes, x, y, 'b-', 'LineWidth', 2);
title(app.UIAxes, 'Plot on UIAxes');
xlabel(app.UIAxes, 'X');
ylabel(app.UIAxes, 'Y');
grid(app.UIAxes, 'on');
% Plot on UIAxes2 (directly on the figure)
plot(app.UIAxes2, x, y, 'r--', 'LineWidth', 2);
title(app.UIAxes2, 'Plot on UIAxes2');
xlabel(app.UIAxes2, 'X');
ylabel(app.UIAxes2, 'Y');
grid(app.UIAxes2, 'on');
end
  • Save and run the App. You will see the linear plot on UIAxes inside a panel and UIAxes2 directly on the figure.
Hope this addresses the query!

3 comentarios

Dong-Gyu
Dong-Gyu el 5 de Dic. de 2024
Thank you for your answer. My code is actually that UIAxes is inside a figure and UIAxes2 is inside a panel (i.e., opposite to your assumption).
However, as you have shown, instead of programatically parenting UIAxes2 to the panel, I moved it to be inside of the panel in Design View, then the linear graph becomes visible in UIAxes2.
If possible, could you tell why the programatical way of parenting UIAxes to the panel does not show the graph in this axes?
axes 2 is not parented to the panel, according to your original posting.
Dong-Gyu
Dong-Gyu el 9 de Dic. de 2024
Hi Walter Roberson.
Do you mean "app.UIAxes2.Parent = app.Panel;" in my original code posted in this question? Is it not parenting UIAxes2 to the Panel?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.

Productos

Versión

R2022b

Preguntada:

el 4 de Dic. de 2024

Comentada:

el 9 de Dic. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by