gui buttongroup

9 views (last 30 days)
Rishabh Kasliwal
Rishabh Kasliwal on 11 Mar 2011
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

Accepted Answer

Walter Roberson
Walter Roberson on 11 Mar 2011
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 Comments
Rishabh Kasliwal
Rishabh Kasliwal on 11 Mar 2011
I am digesting your answer.
I'll try it
thanks
Rishabh Kasliwal
Rishabh Kasliwal on 11 Mar 2011
Digested. It is working :)

Sign in to comment.

More Answers (0)

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!