MATLAB: Need help plotting multiple graphs in one UIAxes

axesguimultiple graphplot

I need help because I can't seem to plot multiple graphs in one UIAxes. Basically there are multiple checkboxes like sine,cosine, and tangent and when multiple boxes are checked they need to be on the UIAxes but I can't figure out a way to do that even when I use hold on function they still only graph one of them. Here's what I've got working
% Button pushed function: Graphb
function GraphbButtonPushed(app, event)
x = str2num(app.Valuesx.Value);
cla(app.UIAxes);
if (app.Plotb.Value == true)
if (app.sinBox.Value == 1)
plot(x,sin(x),'Parent',app.UIAxes)
hold(app.UIAxes,'on')
elseif (app.cosBox.Value == 1)
plot(x,cos(x),'Parent',app.UIAxes)
hold(app.UIAxes,'on')
elseif (app.tanBox.Value == 1)
plot(x,cos(x),'Parent',app.UIAxes)
hold(app.UIAxes,'on')
end
end
end
end

Best Answer

Your if-statement is returning only one option. Try the following way:
function GraphbButtonPushed(app, event)
x = str2num(app.Valuesx.Value);
cla(app.UIAxes);
hold(app.UIAxes,'on')
if (app.Plotb.Value == true)
if (app.sinBox.Value == 1)
plot(x,sin(x),'Parent',app.UIAxes)
end
if (app.cosBox.Value == 1)
plot(x,cos(x),'Parent',app.UIAxes)
end
if (app.tanBox.Value == 1)
plot(x,cos(x),'Parent',app.UIAxes)
end
end
end
end