Radio button to ON-OFF figure visibility

Hello All, I have been working on GUI. Now I am stuck with one requirement, which is to have a radio button to ON-OFF the image visibility. I have the "Calculate" push button which will calculate in user defined loops where I have 3 images per loop. Every time the script runs the image pops up. If the loops are huge in number the calculation process takes more time. So I want to have a radio button so that when selected the images will popup meaning visibility will be ON while unselected, the figures will not pop up so the user can minimize the GUI and work on something else till a message pops up as calculation is completed. I take user defined location to save the images so user will get to the images whenever he wants.
I tried with figure('Visible','off') and it worked well so I just want to add it with a radio button to give user the choice to ON-OFF images.

10 comentarios

Adam
Adam el 18 de Jul. de 2016
Editada: Adam el 19 de Jul. de 2016
What exactly is the problem? Just hook up your radio button in the SelectionChangedFcn to switch the figure visibility on or off if that is how your implementation works. Obviously if you make the figure with the radio button invisible then it will remain that way permanently though as the user will not have any control over it.
adi kul
adi kul el 19 de Jul. de 2016
I am not sure how to do that, can you explain with an example ?
if get(hObject, 'Value')
set(handles.TheFigurehandle, 'Visible', 'on')
else
set(handles.TheFigurehandle, 'Visible', 'off')
end
I have did the following: Under radio button:
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject handle to checkbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox2
if get(hObject, 'Value')
I1.img=1;
else
I1.img=0;
end
set(handles.checkbox2, 'UserData', I1);
Now under Calculate pushbutton I added this before every figure:
if I1.img==1
figure('Visible','off');
else
figure(1);
end
But I am getting this error:
Attempt to reference field of non-structure array.
Walter Roberson
Walter Roberson el 20 de Jul. de 2016
You forgot to pull II out of UserData when you want the value.
I have this in pushbutton:
I1= get(handles.checkbox2, 'UserData');
Walter Roberson
Walter Roberson el 20 de Jul. de 2016
Are you certain that you never invoke the Calculate button before the user has changed the state of the checkbox? Because the default UserData is empty so if the callback has not been invoked the UserData is not going to be a structure.
Your code is not symmetric. In one case you create a new invisible figure and in the other case you raise and make visible figure 1 specifically.
Why are you bothering with the UserData of the checkbox when you can just get its Value which is going to be 0 or 1 anyhow?
adi kul
adi kul el 20 de Jul. de 2016
I am confused on how can I use it's value in push button. can you give the code on how to call it in push button?
Adam
Adam el 20 de Jul. de 2016
Are you using a radio button or a checkbox? Your question talks about a radiobutton, but your code since then suggests you are using a checkbox.
adi kul
adi kul el 20 de Jul. de 2016
I previously tried with checkbox, but could not make it work so someone suggested to make it radio button hence name is still checkbox but the button is radiobutton.

Iniciar sesión para comentar.

 Respuesta aceptada

adi kul
adi kul el 20 de Jul. de 2016
Thank you all for your help. I managed to Solve it using
if get(handles.checkbox2, 'Value')
Visibility = 'on';
else
Visibility = 'off';
end
figure('Visible', Visibility)

Más respuestas (1)

Adam
Adam el 19 de Jul. de 2016
Editada: Adam el 19 de Jul. de 2016
Right click on your radio button group panel (you should put radio buttons in a button panel if they aren't already) and select the SelectionChangedCallback if you are in GUIDE. This will create the function for you then you simply code it as e.g.
set( myFig, 'Visible', hObject.String )
for some figure if you name the options on the radio buttons as 'On' and 'Off'

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Jul. de 2016

Respondida:

el 20 de Jul. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by