Plotting data based on selected checkboxes

I am currently working on malarial cell recognition. In that I have so far succeeded to extract features from the images. There are 49 features in total. I have arranged the features such that each field represents a feature. So the struct feature contains 49 fields. Now i have to generate ksdensity plots for each of the features. For this, I plan to generate a list of checkboxes displayed on the left half of the window with each checkbox having the name of each of the features. When a user selects a checkbox, the corresponding ksdensity plot should be generated on the right half of the figure window. I don't know how to start coding this. Can someone help me? I tried this to create the list of boxes but it is creating from the bottom. I want it from the top.
f= figure;
fields = fieldnames(feature);
for k=1:1:length(fields)
chkbox(k) = uicontrol('Style','checkbox','String',fields{k}, ...
'Value',0,'Position',[30 20*k 130 20], ...
'Callback',{@checkBoxCallback,k});
end
P.S. This is my first ever question on MATLAB Answers. So if something is missing please reply but don't flag :-)

 采纳的回答

Vishnu - I think that part of the confusion with the check boxes being ordered bottom up rather than top down is because of how the figure interprets its "y-axis". The coordinate (0,0) is actually in the bottom left corner of your figure and (0,*h*) is in the top left corner of your figure (where h is the figure height). So if you want to display the check boxes from the top down, then you would do something like
f = figure;
posFig = get(f,'Position');
hFig = posFig(4); % height of the figure
fields = fieldnames(feature);
for k=1:1:length(fields)
chkbox(k) = uicontrol('Style','checkbox','String',fields{k}, ...
'Value',0,'Position',[30 hFig - 20*(k-1) 130 20], ...
'Callback',{@checkBoxCallback,k});
end
In the above, we use the height of the figure to determine where the first check box should go, and each one that follows is just offset from that height (similar to what you tried). Note that it isn't exact and that you may need to determine the optimal height to handle all 49 of your check boxes (you may also want two or three columns for that many controls).
You would then define your callback as
function checkBoxCallback(source, data, index)
% do something
end
where index is the k that will be passed in for each callback. You could also try to just use source which is the handle to the checkbox. For example, if you wish to print out the control string and value (checked which is one or unchecked which is zero) then you would do
function checkBoxCallback(source, data, index)
fprintf('Check box %s is %d\n',get(source,'String'),get(source,'Value'));
end

1 个评论

Thank you so much Geoff. Your answer has got me to get started on that. Just one more question. I want the window to have panes or pretty much a window with subplots where the left pane contains the list of checkboxes and the right pane contains the ksdensity plot of the selected checkboxes. I have the function to generate the ksdensity. Just didn't know how to create the type of window I wanted.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by