필터 지우기
필터 지우기

Matlab Guide checkbox issue

조회 수: 6 (최근 30일)
faiza
faiza 2015년 2월 9일
댓글: faiza 2015년 2월 9일
I am new to matlab and got into an issue.
I have problem with checkboxes in my matlab gui.i am using 3 checkboxes to produce 3 different plots(graphs) on same axes .I want the checkboxes to work in a way that when i check all three of them,i get 3 pots on same graph.But then when i uncheck one say number3,i am now able to see only data for check boxes 1 and 2 . Similarly when i uncheck both 3 and 2,now i should see data of only check box 1. I am able to get data of all three boxes at one time,but when uncheck more than 1 box,the graph doesn't go away?
Any help will be appreciated.

채택된 답변

Image Analyst
Image Analyst 2015년 2월 9일
Just have all three checkbox callbacks call the same function: CheckBoxChecked. Then in that function, clear everything and just plot the data you need to.
function checkbox1_Callback(hObject, eventdata, handles)
CheckBoxChecked(handles);
function checkbox2_Callback(hObject, eventdata, handles)
CheckBoxChecked(handles);
function checkbox3_Callback(hObject, eventdata, handles)
CheckBoxChecked(handles);
function CheckBoxChecked(handles)
cla('reset'); % Erase everything.
state1 = get(handles.checkbox1, 'value');
state2 = get(handles.checkbox2, 'value');
state3 = get(handles.checkbox3, 'value');
if state1
% Plot dataset 1
end
if state2
% Plot dataset 2
end
if state3
% Plot dataset 3
end
  댓글 수: 1
faiza
faiza 2015년 2월 9일
It worked. Thankyou Image Analyst. I never thought about doing it this way.Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2015년 2월 9일
f1=figure;
hold on;
h1=plot(1:10,1:10);
h2=plot(1:10,sin(1:10));
set(h2,'visible','off');
  댓글 수: 1
faiza
faiza 2015년 2월 9일
Hello Jiang, Can you please explain your code.This is the relevant code I am using right now.Where do I use your code ?
*% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data
axes(handles.axes1);
if get(hObject, 'Value')
x=[22;33;44];
y=[10,22,33];
handles.plot = plot(x,y,'r');
hold on
else
delete(handles.plot);
handles.plot = [];
end
guidata(hObject, handles);
and similar code for checkbox2 and checkbox3. Problem is when i have checked all three of the checkboxes,i am able to remove data for only the checkbox that was last checked and the other two boxes won't uncheck.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by