Borrar filtros
Borrar filtros

Matlab Guide checkbox issue

6 visualizaciones (últimos 30 días)
faiza
faiza el 9 de Feb. de 2015
Comentada: faiza el 9 de Feb. de 2015
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.

Respuesta aceptada

Image Analyst
Image Analyst el 9 de Feb. de 2015
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 comentario
faiza
faiza el 9 de Feb. de 2015
It worked. Thankyou Image Analyst. I never thought about doing it this way.Thanks

Iniciar sesión para comentar.

Más respuestas (1)

Fangjun Jiang
Fangjun Jiang el 9 de Feb. de 2015
f1=figure;
hold on;
h1=plot(1:10,1:10);
h2=plot(1:10,sin(1:10));
set(h2,'visible','off');
  1 comentario
faiza
faiza el 9 de Feb. de 2015
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by