plot hold on in GUI

267 vues (au cours des 30 derniers jours)
JB
JB le 11 Août 2017
I am new to matlab and need a bit of help with a gui. I have two axes boxes (axes2 and axes3) where I use checkmarks to plot within. First checkbox creates two plots: one (x1,y1) in axes2 and the second (x1,ht) in axes3. The second checkbox also creates two plots: one(x2,y2) in axes2 and the second (x2,ht2) in axes3. I want to Hold on to the figures, so if I select both checkmarks both axes2 and axes3 will contain two plots. However, only axes2 work. In axes3 only show the plot connected to the last selected chechmark.
Please help. The code is below:
function checkbox1_Callback(hObject, eventdata, handles)
if get(handles.checkbox1,'Value')
hold on;
handles.hCbox1Plot = plot(x1,y1,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes2);
hold on;
handles.hCbox2Plot = plot(x1,ht,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes3);
guidata(hObject,handles); % do this to save the updated handles structure
else
if ~isempty(handles.hCbox1Plot);
~isempty(handles.hCbox2Plot);
delete(handles.hCbox1Plot);
delete(handles.hCbox2Plot);
end
end
function checkbox2_Callback(hObject, eventdata, handles)
if get(handles.checkbox2,'Value')
hold on;
handles.hCbox3Plot = plot(x2,y2,'LineWidth',2,'Color', [1 0 0],'parent',handles.axes2);
hold on;
handles.hCbox4Plot = plot(x2,ht2,'LineWidth',2,'Color', [1 0 0],'parent',handles.axes3);
guidata(hObject,handles); % do this to save the updated handles structure
else
if ~isempty(handles.hCbox3Plot);
~isempty(handles.hCbox4Plot);
delete(handles.hCbox3Plot);
delete(handles.hCbox4Plot);
end
end

Réponse acceptée

Adam
Adam le 11 Août 2017
Modifié(e) : Adam le 11 Août 2017
doc hold
shows that you can call hold with an axes handle. You should always do this e.g.
hold( handles.axes2, 'on' )
It is far better than just calling
hold on
and hoping for the best that it will apply to the axes you expect.
  5 commentaires
Diego Magpayo
Diego Magpayo le 4 Fév 2021
you are a GOD
ali florez pedraza
ali florez pedraza le 28 Déc 2023
hold( handles.axes2, 'off' )

Connectez-vous pour commenter.

Plus de réponses (1)

karim botros
karim botros le 26 Sep 2018
for the new app designer
you can you use
ax0=app.UIAxes; %Assign your axes to variable
hold( ax0, 'on' )
%plot as much as you want
hold( ax0, 'off' )

Catégories

En savoir plus sur 2-D and 3-D Plots 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