plot hold on in GUI

264 次查看(过去 30 天)
JB
JB 2017-8-11
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

采纳的回答

Adam
Adam 2017-8-11
编辑:Adam 2017-8-11
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 个评论
ali florez pedraza
ali florez pedraza 2023-12-28
hold( handles.axes2, 'off' )

请先登录,再进行评论。

更多回答(1 个)

karim botros
karim botros 2018-9-26
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' )

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by