Need help plotting multiple graphs in one UIAxes

5 vues (au cours des 30 derniers jours)
Sean Patrick Catibog
Sean Patrick Catibog le 26 Avr 2019
Réponse apportée : G A le 26 Avr 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

Réponse acceptée

G A
G A le 26 Avr 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

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Objects dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by