check box GUI and grapsh
11 views (last 30 days)
Show older comments
I'm back again, becouse I'm still working on my gui;
Now I've the following question:
In my gui I've placed 6 check box;
each check box if is actived shall plot a graphs;
Of course what I want is each time that I select a check box the graph shall plot data that coming from different matrix:
EX: given six matrix A1,A2,A3,A4,A5,A6
and six check box (c1,c2,c3,..c6) if for example I select c1 and c2 I want a graphs with both data;
I tried to create the condictions with a cicle 'If ' but I understood that this will be a little complicated becouse I have to consider 64 different condictions....(2 elevated to the sixth...)
is there any easiest way to do that???
4 Comments
Sarah Crimi
on 19 Dec 2018
Edited: Sarah Crimi
on 19 Dec 2018
You only want A1 through A6, right? Then, 64-6 solutions should be error messages. I think it is better to do radio buttons possibly because then you can use a radio button group in guide.
If you want to do checkboxes, you could do:
if(Sector1==1 & Sector2==0 & Serctor3==0 & Sector4==0 & Sector5==0 & Serctor6==0)
plot (A1(:,1),A1(:,2))
elseif(Sector1==0&Sector2==1 &&Serctor3==0 & Sector4==0 & Sector5==0 & Serctor6==0)
plot (A2(:,1),A2(:,2))
elseif (Sector1==0&Sector2==0 &&Serctor3==1 & Sector4==0 & Sector5==0 & Serctor6==0)
plot (A3(:,1),A3(:,2))
....etc.
else
msgbox('Error');
end
Accepted Answer
Luna
on 20 Dec 2018
Edited: Luna
on 20 Dec 2018
I recommend you write 6 callbacks for each checkbox, and check the value of checkbox.
So any time a checkbox is checked it plots to your figure, and any time it is unchecked it deletes the line you referenced.
function chkbox1_Callback(guiobj,chckboxObj,varargin)
if checkbox1Obj.value == 1
guiobj.line1 = plot(X1,Y1,'Parent',guiobj.figure); % also store your line variable, figure variable under the gui object
hold on; % hold it for any other check boxes pressed.
else
delete(guiobj.line1);
end
end
Note:
While creating your uicontrol element put callback property like below to get your guiobject as first input reference in above callback. The second input will be your checkbox object.
uicontrol('Parent', guiobj.figure, 'style', 'checkbox', 'Callback', @guiobj.chkbox1_Callback);
Note2:
You should have a classdef of guiobj which has properties of figure,line1,line2,..etc.
2 Comments
Luna
on 26 Dec 2018
Let me explain the difference.
1) If you create your uicontrol's callback like below:
uicontrol(.. .., 'Callback', @guiObj.chkbox1_Callback)
and then define your callback as follows:
function chkbox1_Callback(guiObj,chckboxObj,eventdata)
% first input is guiObj which is the handle of main gui object(you can store any other user defined data to properties of guiObj )
% second input is chckboxObj which is the handle of checkbox uicontrol element. You can change its value (check, uncheck,enable,disable,..etc) and any other things.
% third input is eventdata (actiondata of )
end
2) If you create your uicontrol's callback like below:
uicontrol(.. .., 'Callback', @chkbox1_Callback)
and then define your callback as follows:
function checkbox1_Callback(hObject, eventdata, handles)%what I used
% first input is hObject which is your checkbox obj
% second input is eventdata which is the action data
% third is the handles which is the common handles of main gui some information can be stored in here to share data.
% if you are using GUIDE generally built-in guidata function you can use to store and get data whenever you wanted.
end
read this for more explanation:
I personally do not use GUIDE, so I prefer to do in the first option I have explained. I built my own structure and my own uicontrol elements one by one myself.
To delete your plot lines whenever the checkbox clicked, if it is unchecked, you should call a delete function. To do so, while plotting you should store the line you have plotted in somewhere you can always reach. (Like a common handle). Also I recommend you to store axes handle in some field, too. So you can manipulate the axes whenever you need.
function checbox_1_callback(hObj,event,handles)
if hObj.Value == 1
handles.Line1 = plot(..); % this stores your plotted line under handles.line1
else
delete(handles.Line1);
end
end
for me I store them under guiObj which I defined this class and its properties as I wish. You can choose whatever you want.
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!