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:
Drop down menus

Subject: Drop down menus

From: spu00crm@volcanomail.com (Jess)

Date: 16 Aug, 2001 12:10:00

Message: 1 of 7

I am using Matlab 4 have written the following code for a drop down
menu:

btnNumber=1;
    yPos=top-(btnNumber-1)*(btnHt+spacing);
    btnPos=[left yPos-btnHt btnWid btnHt];
    labelList=str2mat( ...
'Select A Demo', ...
'Exercise 3', ...
'Exercise 4', ...
'Exercise 5');
    openHndl=uicontrol( ...
        'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList);

I do not know now what to do to get one of the three options (exercise
3, 4 or 5) to do something when they are clicked upon. I am new to
programming and so I do not know Matlab very well at all.

Subject: Drop down menus

From: lg@2-control.com (Lars Gregersen)

Date: 17 Aug, 2001 05:21:41

Message: 2 of 7

On 16 Aug 2001 12:10:00 -0700, spu00crm@volcanomail.com (Jess) wrote:

>I am using Matlab 4 have written the following code for a drop down
>menu:
>
>btnNumber=1;
> yPos=top-(btnNumber-1)*(btnHt+spacing);
> btnPos=[left yPos-btnHt btnWid btnHt];
> labelList=str2mat( ...
> 'Select A Demo', ...
> 'Exercise 3', ...
> 'Exercise 4', ...
> 'Exercise 5');
> openHndl=uicontrol( ...
> 'Style','popup', ...
> 'Units','normalized', ...
> 'Position',btnPos, ...
> 'String',labelList);
>
>I do not know now what to do to get one of the three options (exercise
>3, 4 or 5) to do something when they are clicked upon. I am new to
>programming and so I do not know Matlab very well at all.

You have to add a callback property to your call to uicontrol.
Something like:

    openHndl=uicontrol( ...
        'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelList
                  'callback','disp(get(gcb,''value''))');

This is untested since I don't have a Matlab 4 anymore.

  Lars


Lars Gregersen
2-control ApS
E-mail: lg@2-control.com
Web: www.2-control.com

Subject: Drop down menus

From: Jess

Date: 17 Aug, 2001 09:22:06

Message: 3 of 7

Thanks for that, I have tried it and it does work. I would never have
worked that out!

Subject: Drop down menus

From: lg@2-control.com (Lars Gregersen)

Date: 18 Aug, 2001 05:56:47

Message: 4 of 7

On Fri, 17 Aug 2001 09:22:06 +0100, "Jess" <none@none.com> wrote:

>Thanks for that, I have tried it and it does work. I would never have
>worked that out!

It's the general idea about controls. Everytime you need the control
to do something when something happen it need to know where to go.
Matlab uses callback functions for this. You may want to search this
group for the word "switchyard". It will give you some examples of how
to handle many of such callback in an efficient manner.

  Lars


Lars Gregersen
2-control ApS
E-mail: lg@2-control.com
Web: www.2-control.com

Subject: Drop down menus

From: Jess

Date: 18 Aug, 2001 12:08:31

Message: 5 of 7

I have a few problems, firstly I have writtten the following code:
    openHndl=uicontrol( ...
        'Style','popup', ...
 'Units','normalized', ...
 'Position',btnPos, ...
 'String',labelList, ...
 'callback','setEx')

So this is then sent to an m file called setEx which starts:
    val=get(openHndl,'Value');
    if val==2
so how do you make it open an m file directly? Also after one of the
options in the open list is pressed another window is opened, how do make
the initial window then close automatically?

Subject: Drop down menus

From: Jess

Date: 18 Aug, 2001 16:40:22

Message: 6 of 7

I have managed to now open the m file but I still do not know how to make
the other window disappear. But the value of the openHndl always appears on
the Malab screen and I do not know how to get rid of it.

Subject: Drop down menus

From: lg@2-control.com (Lars Gregersen)

Date: 19 Aug, 2001 06:11:30

Message: 7 of 7

On Sat, 18 Aug 2001 12:08:31 +0100, "Jess" <none@none.com> wrote:

>I have a few problems, firstly I have writtten the following code:
> openHndl=uicontrol( ...
> 'Style','popup', ...
> 'Units','normalized', ...
> 'Position',btnPos, ...
> 'String',labelList, ...
> 'callback','setEx')
>
>So this is then sent to an m file called setEx which starts:
> val=get(openHndl,'Value');

You are probably going to find that the line above doesn't work. This
is because the variable openHndl doesn't exist inside your function
setEx. Use this line to get the handle

openHndl = findobj('callback','setEx')

> if val==2
>so how do you make it open an m file directly? Also after one of the

opening files: uigetfile

>options in the open list is pressed another window is opened, how do make
>the initial window then close automatically?

You close a windows using the function CLOSE.

  Lars


Lars Gregersen
2-control ApS
E-mail: lg@2-control.com
Web: www.2-control.com

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