Two plots on same axes using guide

조회 수: 1 (최근 30일)
Ghufran Aldawood
Ghufran Aldawood 2018년 10월 31일
편집: Ghufran Aldawood 2018년 10월 31일
Hello!
I have two global variables y & z that I am wanting to plot against the same x-axis. The GUI has two check boxes one to plot y and the other to plot z. I want to be able to show both plots at the same time so that I can compare the two. But I am also wanting them to show if and only if I check the box assigned to the global variable.
right now the code shows one plot if I click checkbox1, but that plot disappears when I click checkbox2 and only checkbox2 plot would show. I tried to use hold on, as well as hold(handles.axes1,'on') but that didn't work.
here is the code:
function checkbox1_Callback(hObject, eventdata, handles)
gatherAndUpdate(handles)
function gatherAndUpdate(handles)
gatheredData = gatherData(handles);
updateAxes(handles.axes1,gatheredData);
function gatheredData = gatherData(handles)
gatheredData.PlotData = get(handles.checkbox1,'value');
function updateAxes(axesToUse,gatheredData)
handles.axes1=(axesToUse)
if gatheredData.PlotData
x=linspace(5,20,120000);
global y
axes(handles.axes1)
plot(x,y);
else
x=linspace(5,20,120000);
set(plot(x,y),'visible','off')
end
function checkbox2_Callback(hObject, eventdata, handles)
gatherAndUpdate2(handles)
function gatherAndUpdate2(handles)
gatheredData2 = gatherData2(handles);
updateAxes2(handles.axes1,gatheredData2);
function gatheredData2 = gatherData2(handles)
gatheredData2.PlotData = get(handles.checkbox2,'value');
function updateAxes2(axesToUse,gatheredData2)
handles.axes1=(axesToUse)
if gatheredData2.PlotData
x=linspace(5,20,120000);
global z
axes(handles.axes1)
plot(x,z);
else x=linspace(5,20,120000);
set(plot(x,z),'visible','off')
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by