Need help plotting multiple graphs in one UIAxes

11 Ansichten (letzte 30 Tage)
Sean Patrick Catibog
Sean Patrick Catibog am 26 Apr. 2019
Beantwortet: G A am 26 Apr. 2019
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

Akzeptierte Antwort

G A
G A am 26 Apr. 2019
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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by