Looking to generate an array (grid) of pushbuttons in a figure
57 views (last 30 days)
Show older comments
Hello All,
I am trying to generate a grid of pushbuttons in a figure. I will prompt the user, and get a numeric value of the grid size, and then generate said grid. For example, if the user enters 25, the script will generate 25 push buttons in a 5x5 grid. The user will then select one or more of these buttons, and then once another button ('GO' for example) is pressed, I will get the values of the numbers in the grid to use for another purpose. Anyone know how the best way to go about this? Searching hasnt gotten me too far, so any help would be greatly appreciated.
Also, I am using Matlab 2015b.
Thanks!
-J
4 Comments
Geoff Hayes
on 18 Apr 2019
Ruger28 - is there a maximum number of pushbuttons allowed? Have you created a GUI in GUIDE that prompts the user for the number of buttons? Would the 5x5 grid of buttons be contained within that GUI or a separate one?
Accepted Answer
Geoff Hayes
on 18 Apr 2019
Edited: Geoff Hayes
on 18 Apr 2019
Ruger28 - you can get the string value of the button from within the callback. Just remove the input (kk?) as an input parameter to the callback
hText(i) = uicontrol('Style','pushbutton','String',[num2str(i)],...
'Parent',hGroup,'Units','normalized','Position',[xpos ypos .05 .05],...
'BackgroundColor','white','Callback',{@pushbutton_callback});
and your callback would just be
function pushbutton_callback(hObject, hEvent)
id = str2double(get(hObject,'String'));
where id is the number on the button.
You're right, the callback won't output anything but if you nest your callback within a parent function then perhaps you can update a variable declared in the parent function that can then be used elsewhere...or if you are using GUIDE, then you can probably update the handles structure so that other callbacks in your GUI have access to it.
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!