Creating table of toggle buttons
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Krishna Zanwar
2019년 2월 27일
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
Krishna Zanwar
2019년 3월 1일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!