gui buttongroup

1 回表示 (過去 30 日間)
Rishabh Kasliwal
Rishabh Kasliwal 2011 年 3 月 11 日
Hello All,
My question is regarding the callback function of a button group. MATLAB states that one can write such a function and whenever a button is selected in the button group, this function is automatically executed. My 'selbck' function is working properly but.... when I set the value of a particular button in the button group to '1' using command line, the callback is not called.
is there a way of doing so ?
For example
1. The button group callback is 'selbckevent'
2. I have an event list: 'imaged', 'uncaged', with handles 'imageh', 'uncageh'
3. If I press the buttons, selbckevent is excecuted, if I write 'set(imageh, 'Value', 1)' it is NOT executed
please help
rishabh

採用された回答

Walter Roberson
Walter Roberson 2011 年 3 月 11 日
There might be a way involving property listeners, but it is typical and usually desirable that callbacks not automatically be invoked when properties are set().
You can manually invoke the callback:
cb = get(imageh,'Callback');
if ~isempty(cb)
if ischar(cb)
feval(cb, imageh, struct());
elseif isa(cb, 'function_handle')
cb(imageh, struct());
elseif iscell(cb)
cb{1}(imagesh, struct(), cb{2:end});
else
error(['imageh callback has unexpected properties, class ', ...
class(cb)]);
end
end
The code can be shortened a lot if you make assumptions about what the callback will be coded as.
You may have noticed that I passed struct() as the event data. Some callbacks have non-empty event data needed in order to work properly. When you are changing the value of a property via set(), you are not doing so in reaction to an event that you can get the necessary values from. Your callback would need to be coded to handle this situation, or you would need to pass in fake event information.
(You see now why the callback is not invoked automatically when you set() ?)
  2 件のコメント
Rishabh Kasliwal
Rishabh Kasliwal 2011 年 3 月 11 日
I am digesting your answer.
I'll try it
thanks
Rishabh Kasliwal
Rishabh Kasliwal 2011 年 3 月 11 日
Digested. It is working :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by