Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How can I ctivate uibutton selectionchangefcn programmatically

Subject: How can I ctivate uibutton selectionchangefcn programmatically

From: Camille Couzi

Date: 8 Nov, 2010 20:26:04

Message: 1 of 6

Hi!
I would like to know if it is possible to call the selectionchange fcn of a uibuttongroup which is in a fig1, from a fig2, ie how to activate the callback when choosing one of the buttons, in different way rather than pressing this button (so programmatically)
Thanks for your ideas!

Camille.

Subject: How can I ctivate uibutton selectionchangefcn programmatically

From: Walter Roberson

Date: 8 Nov, 2010 20:58:38

Message: 2 of 6

On 10-11-08 02:26 PM, Camille Couzi wrote:

> I would like to know if it is possible to call the selectionchange fcn
> of a uibuttongroup which is in a fig1, from a fig2, ie how to activate
> the callback when choosing one of the buttons, in different way rather
> than pressing this button (so programmatically)

%if necessary, use findobj() relative to fig2 in order to find
%the handle of the button group. Then,

selfun = get(TheUibuttonHandle, 'SelectionChangeFcn');
oldsel = get(TheUibuttonHandle, 'SelectedObject');
newsel = ... %the button you want to be selected
fakeevent = struct('EventName', 'SelectionChanged', ...
   'OldValue', oldsel, ...
   'newValue', newsel);
selfun{1}(TheUibuttonHandle, fakeevent, selfun{2:end});

Subject: How can I ctivate uibutton selectionchangefcn programmatically

From: Camille Couzi

Date: 9 Nov, 2010 12:22:13

Message: 3 of 6

Hi Walter,
Thanks a lot for your answer. One question: did you forget an "=" in the last line:
selfun{1}=(TheUibuttonHandle, fakeevent, selfun{2:end}); ???

I get an error:

Warning: To support parenthesis notation for invocation, "indexing" a scalar
 function handle by "end" will continue to work in R2007a, but may be invalid or may
 work differently in future releases of MATLAB. To avoid this warning and
 possible future errors, use cell arrays of function handles instead of arrays.
 For more information, type 'help function_handle' and see the section at the end
 entitled "Note on Backward Compatibility."
> In Figura_Polares>Ver_en_grafica at 442
??? Cell contents reference from a non-cell array object.

Error in ==> Figura_Polares>Ver_en_grafica at 442
scf_plot1{1}(h.panel_plot1, fakeevent, scf_plot1{2:end});

??? Error while evaluating uicontrol Callback

also, what do you put in: newsel =... ? it is the handle of the button I want to be selected, right?

Thanks again for your help!
Camille.

Subject: How can I ctivate uibutton selectionchangefcn programmatically

From: Walter Roberson

Date: 9 Nov, 2010 18:35:08

Message: 4 of 6

On 09/11/10 6:22 AM, Camille Couzi wrote:

> I get an error:
>
> Warning: To support parenthesis notation for invocation, "indexing" a
> scalar
> function handle by "end" will continue to work in R2007a, but may be
> invalid or may
> work differently in future releases of MATLAB.

> scf_plot1{1}(h.panel_plot1, fakeevent, scf_plot1{2:end});

It appears you have defined the callback via

uibuttongroup( ..., 'SelectionChangeFcn', @Ver_en_grafica})

Change this to

uibuttongroup( ..., 'SelectionChangeFcn', {@Ver_en_grafica})

for the more general version of the code. Alternately, if you can be
sure that you are always going to use a single function handle and not
want to pass additional arguments through the cell array syntax, you
could leave the uibuttongroup() call as is, and change the callback
invocation line to

scf_plot1(h.panel_plot1, fakevent);


> also, what do you put in: newsel =... ? it is the handle of the button I
> want to be selected, right?

Yes.
http://www.mathworks.com/help/techdoc/ref/uibuttongroupproperties.html#bqxp5rd

Subject: How can I ctivate uibutton selectionchangefcn programmatically

From: Camille Couzi

Date: 11 Nov, 2010 15:29:05

Message: 5 of 6

Hi Walter,

Ok, so I have written, following all your indications:

scf_plot1 = get(h.panel_plot1, 'SelectionChangeFcn');
oldsel = get(h.panel_plot1, 'SelectedObject');
newsel = h.boton_post_plot1_V;
fakevent = struct('EventName', 'SelectionChanged', ...
   'OldValue', oldsel, 'newValue', newsel);
scf_plot1(h.panel_plot1, fakevent);

(and changed the { } brackets in the selection change function of my uibuttongroup h.panel_plot1).
I get errors related to thing that I have written in my uibuttongroup selection change function, because in that function, I have the normal part with the "switch case...", and a second part where I get other button values, make more calculations...
So my question here is: Do I have to separate my actual selection chge fcn and keep in it the switch... part, and in another function put all my other calculations? I that way, would I get rid of the errors?

Thanks for you help
Camille.

Subject: How can I ctivate uibutton selectionchangefcn programmatically

From: Sara

Date: 11 Sep, 2012 18:31:08

Message: 6 of 6

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <ibh241$ra7$1@fred.mathworks.com>...
> Hi Walter,
>
> Ok, so I have written, following all your indications:
>
> scf_plot1 = get(h.panel_plot1, 'SelectionChangeFcn');
> oldsel = get(h.panel_plot1, 'SelectedObject');
> newsel = h.boton_post_plot1_V;
> fakevent = struct('EventName', 'SelectionChanged', ...
> 'OldValue', oldsel, 'newValue', newsel);
> scf_plot1(h.panel_plot1, fakevent);
>
> (and changed the { } brackets in the selection change function of my uibuttongroup h.panel_plot1).
> I get errors related to thing that I have written in my uibuttongroup selection change function, because in that function, I have the normal part with the "switch case...", and a second part where I get other button values, make more calculations...
> So my question here is: Do I have to separate my actual selection chge fcn and keep in it the switch... part, and in another function put all my other calculations? I that way, would I get rid of the errors?
>
> Thanks for you help
> Camille.

I don't know the answer, sounds to me like it should work. The reason I'm writing is that I couldn't get your code to work. Here's what worked for me.

oldsel = get(handles.ui_button_panel 'SelectedObject');
newsel = handles.new_radiobutton;
fakevent = struct('EventName', 'SelectionChanged', 'OldValue', oldsel, 'NewValue', newsel);
ui_button_panel_SelectionChangeFcn(handles.ui_button_panel, fakevent, handles)

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us