Need help plotting multiple graphs in one UIAxes

조회 수: 5 (최근 30일)
Sean Patrick Catibog
Sean Patrick Catibog 2019년 4월 26일
답변: G A 2019년 4월 26일
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

채택된 답변

G A
G A 2019년 4월 26일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by