Two plots on same axes using guide

1 visualizzazione (ultimi 30 giorni)
Ghufran Aldawood
Ghufran Aldawood il 31 Ott 2018
Modificato: Ghufran Aldawood il 31 Ott 2018
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

Risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by