Need help with Checkbox GUI

Hello All,
I am planning to have a checkbox in my GUI which will give user a flexibility over turning "on" and "off" the figures popups.
What I want is, by default the checkbox should be checked where the plots will popup every time the script runs over the loop. But by checking it OFF, the figure visibility will be off so user may minimize the GUI and do other stuff without getting disturbed.
I am unable to add the logic. Can anyone help me with a quick code? The script runs in a different call back function.

1 Kommentar

adi kul
adi kul am 13 Jun. 2016
This is what I tried:
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (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 checkbox1
S5.checkboxStatus = get(h.checkbox1,'Value');
set(handles.checkbox1,'UserData', S5);
and in my figures:
if S5.checkboxStatus==1
figure(1);
else
figure ('Visible','off');
But this giving me error:
Attempt to reference field of non-structure array.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 13 Jun. 2016

0 Stimmen

show_the_figure = get(handles.checkbox, 'value') == 1;
if show_the_figure
set(AppropriateFigurehandle, 'visible', 'on')
else
set(AppropriateFigurehandle, 'visible', 'off')
end

3 Kommentare

adi kul
adi kul am 13 Jun. 2016
Bearbeitet: adi kul am 13 Jun. 2016
Actually in Checkbox GUI [in GUIDE], I made the value 1. So now by default the checkbox is Checked.
And I don't have different handles for figures. They are the part of pushbutton.
So this is what I tried:
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (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 checkbox1
S5.checkboxStatus = get(h.checkbox1,'Value');
set(handles.checkbox1,'UserData', S5);
and in push button callback where the figure is, I added this:
if S5.checkboxStatus==1
figure(1);
else
figure ('Visible','off');
But this giving me error:
Attempt to reference field of non-structure array.
You stored S5 in the UserData of handles.checkbox1 and to use it you are going to need to retrieve it from there,
S5 = get(handles.checkbox1, 'UserData');
However, for this to work properly you are going to need to know that you ran the checkbox callback at least once before the pushbutton was active, or that you initialized the UserData of handles.checkbox1 before the pushbutton is active, or you use
if isempty(S5) || S5.checkboxStatus==1
set(1, 'Visible', 'on');
else
set(1, 'Visible', 'off');
end
"And I don't have different handles for figures. They are the part of pushbutton."
When you set the figure visbility off so that you do not show the plot, that will take the checkbox and all other controls with it, making them all invisible, because the are part of the figure as well. How are you going to get them back?
adi kul
adi kul am 13 Jun. 2016
actually I am saving the figures to a directory. So I don't have any handles for figures.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 13 Jun. 2016

Kommentiert:

am 13 Jun. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by