Plot visibility by checkmark in GUI

2 ビュー (過去 30 日間)
JB
JB 2017 年 9 月 27 日
編集済み: JB 2017 年 9 月 27 日
I have from 2-30 plots where I want to control the visibility by checkmark selection in a GUI (Guide). But I can't get it to work. Please help.
Here my code with two simple plots:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
X1=[1 2 3 4]
Y1=[-1 -2 -3 -4]
X2=[1 2 3 4]
Y2=[1 2 3 4]
handles.handle_plot1 = plot(X1,Y1);
handles.handle_plot2 = plot(X2,Y2);
guidata(hObject, handles);
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
handle_plot1 = handles.handle_plot1
if (get(hObject,'Value')) == 1
set(handle_plot1, 'visible' , 'on')
else
set(handle_plot1, 'visible' , 'off')
end
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
handle_plot2 = handles.handle_plot2
if (get(hObject,'Value')) == 1
set(handle_plot2, 'visible' , 'on')
else
set(handle_plot2, 'visible' , 'off')
end
But I get this error:
Error using matlab.graphics.chart.primitive.Line/set
Invalid or deleted object.
Error in test>checkbox1_Callback (line 91)
set(handle_plot1, 'visible' , 'on')
What am I doing wrong?

採用された回答

Jan
Jan 2017 年 9 月 27 日
If plot works in an axes with 'NextPlot' set to 'replace' (the default), a new plot replaces the old plot completely. Try this:
function pushbutton1_Callback(hObject, eventdata, handles)
X1=[1 2 3 4];
Y1=[-1 -2 -3 -4];
X2=[1 2 3 4];
Y2=[1 2 3 4];
set(gca, 'NextPlot', 'add'); % Equivalent to: hold('on')
handles.handle_plot1 = plot(X1,Y1);
handles.handle_plot2 = plot(X2,Y2);
guidata(hObject, handles);
  1 件のコメント
JB
JB 2017 年 9 月 27 日
編集済み: JB 2017 年 9 月 27 日
This is great thanks (again) Jan Simon. It is great.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by