plot hold on in GUI

조회 수: 269 (최근 30일)
JB
JB 2017년 8월 11일
댓글: ali florez pedraza 2023년 12월 28일
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
Diego Magpayo
Diego Magpayo 2021년 2월 4일
you are a GOD
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