フィルターのクリア

plot hold on in GUI

197 ビュー (過去 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 Center および File Exchange2-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