MATLAB: Unable to plot multiple graphs on same UIAxes (Matlab AppDesigner)

appdesignergraphholdmatlab app designermatlab guimultipleplotuiaxes

Please see my UI attahced. (Matlab App Designer)
I am importing CSV files and plotting each of the three variables(column vectors on Y Axis) against length(X axis). By using checkboxes, I want the user to specify which variables(Y axis) to plot against length(X Axis). Also by importing multiple files, the user should be plot files on same graph. For eg. import 10 files, and plot load vs length in the same graph or UIAxes. However, UIAxes is not responding as expected. It sometimes plots only 4, sometimes 2 and erases the rest of them. In short, it is unable to plot every plot that I want on the same plot.
(You can skip the code and go directly to the Plot section)
Here's my code when pushbutton(Plot) is pressed:
[filename,~] = uigetfile('*.csv;','MultiSelect','on');
s = size(filename);
s = s(1,2);
f = 1;
for f = 1:s
Raw=xlsread(char(filename(f)));
TestLength = app.TestLength.Value;
Points = app.NoofPoints.Value;
%Assigning columns to variables
RawTime = Raw(:,1);
RawExtension = Raw(:,2);
RawLoad = Raw(:,3);
%Calculating Profile
Distance= TestLength/(Points-1);
Length_Points= linspace(0,TestLength,Points);
% Removing slack
RawLoad(RawLoad<10)=0;
%findpeaks(RawLoad,RawTime,'Annotate','extents','WidthReference','halfheight');
[peaks,ind] = findpeaks(RawLoad);
P = size(peaks);
P = P(1);
i=1;
for i=1:P
ext(i)=RawExtension(ind(i),1);
end
%Stiffness
stiffness = peaks./ext';
if app.LoadCheckBox.Value==1
yyaxis (app.UIAxes,'left')
plot(app.UIAxes,Length_Points(1:P),peaks,'-')
ylim(app.UIAxes,[0 600]);
xlim(app.UIAxes,[0 TestLength]);
hold(app.UIAxes);
end
if app.StiffnessCheckBox.Value==1
yyaxis (app.UIAxes,'left')
plot(app.UIAxes,Length_Points(1:P),stiffness,'--')
xlim(app.UIAxes,[0 TestLength]);
hold(app.UIAxes);
end
if app.ExtensionCheckBox.Value==1
yyaxis (app.UIAxes,'right')
plot(app.UIAxes,Length_Points(1:P),ext,':')
ylim(app.UIAxes,[0 10]);
xlim(app.UIAxes,[0 TestLength]);
hold(app.UIAxes);
end
end

Best Answer

In appDesigner, you would use the hold(ax,___) syntax.
For example, in one of my apps, I do the following:
hold(app.UIAxes,'on')
app.Sa_avg = plot(app.UIAxes, app.pO2, SaO2_avg,':k');
app.Sa = plot(app.UIAxes, app.pO2, SaO2);
hold(app.UIAxes,'off')