フィルターのクリア

Creating table of toggle buttons

2 ビュー (過去 30 日間)
Luis Chaves
Luis Chaves 2019 年 2 月 23 日
コメント済み: Krishna Zanwar 2019 年 3 月 1 日
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

回答 (1 件)

Krishna Zanwar
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 件のコメント
Luis Chaves
Luis Chaves 2019 年 3 月 1 日
Hello Krishna,
Thank you for your reply, I am not very familiar with the use of hObject, I am using the structure S to save everything related to the pushbuttons, would I need to create S.hObject?
Could you provide some sample code of what the callback function would look like?
Best,
Luis
Krishna Zanwar
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 ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by