Clear Filters
Clear Filters

How to stop the first plot from overwriting the second plot in app.Panel when using Tiledlayout? "Hold on" does not work.

6 views (last 30 days)
The below is my code, it should plot 5 graphs in one figure using the tiledlayout function. Each graph should have a red line and blue circles. If I run the below, without the app.Panel portion in the command line, I get the expected graph. However, when add in app.Panel so the plot shows up in my matlab app, I only get the second plot with the red line, the first plot with the blue circles is gone.
Anyone know a solution to this? Thanks!
x=1:1:10;
y=2:2:20;
x_values=1:3:30;
y_values=1:2:20;
t=tiledlayout(app.Panel,1,5);
for c=1:5
ax=nexttile(t);
plot(ax,x,y,'o', 'MarkerSize', 10, 'LineWidth', 2 ,'color','b');
hold on;
plot(ax, x_values, y_values, 'r', 'LineWidth', 2);
title(ax,'test');
xlabel(ax,'Setting Value'); % Add title for X axis
ylabel(ax,'Test Factor'); % Add title for Y axis
hold off;
end

Accepted Answer

Cris LaPierre
Cris LaPierre on 6 May 2024
In App Designer, you must specify which axes to hold on by using the syntax hold(ax,___).
Try this
hold(ax,'on')

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!