Creating table of toggle buttons
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello!
I am trying to create a table of toggle buttons so that when a button is pressed the value of that cell in an equivalent matrix to the table is changed. My question is: Do I need one callback function for each button or can I use a single function that handles the pressing/unpressing of any button in the table? If I need one callback function per button what is the best way to do so? Can I define callback function in the loops that build the table?
Here is my code (the callback function is not yet built):
S.fh = figure('units','pixels',...
'position',[200 200 30*12 30*8],...
'menubar','none',...
'numbertitle','off',...
'name','Well selection',...
'resize','on');
count = 1;
for a = 1:12
for b = 1:8
S.pb(a,b) = uicontrol('style','toggle',...
'units','pixels',...
'position',[30*(a-1) 240-30*b 30 30],...
'fontsize',14,...
'string',num2str(count),...
%The callback function is below, Would it be possible to define this callback function iteratively?
'callback',{@pb_call,S});
count = count +1;
end
end
0 Kommentare
Antworten (1)
Krishna Zanwar
am 27 Feb. 2019
Hey Luis,
A single function can be used for callback of all the toggle buttons.
The button which was pressed can be recognized by-
get(hObject,'String')
The value of the button that was pressed can be displayed by-
get(hObject,'Value')
The pb_call function will be called when any button is pressed.
2 Kommentare
Krishna Zanwar
am 1 Mär. 2019
Add this to your code and it will save the string of toggle button in 'Number' and the value of that button in 'Value'
function pb_call(hObject,a,b)
Number=get(hObject,'String')
Value=get(hObject,'Value')
end
You should get more information about callbacks here.
Hope it helps.
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!