Matlab GUI Tutorial - Pop-up Menu
29 Oct 2007 Quan Quach 91 comments 18,690 views
Introduction
In this Matlab GUI tutorial, you will learn how to create and use the Pop-up Menu component. Pop-up menus are used as a control for choosing between a set of options. When the user clicks on the Pop-up menu, the menu expands, revealing a set of choices that the user can pick. A common use for Pop-up menus is a font size selector (shown below).

This tutorial is written for those with little or no experience creating a Matlab GUI (Graphical User Interface). If you’re new to creating GUIs in Matlab, you should visit this tutorial first. Basic knowledge of Matlab is not required, but recommended. Matlab version 2007a is used in writing this tutorial. Both earlier versions and new versions should be compatible as well (as long as it isan’t too outdated). Let’s get started!
Create the Visual Aspect of the GUI
-
First, open up Matlab. Go to the command window and type in
guide.
-
You should see the following screen appear. Choose the first option
Blank GUI (Default).
-
Click on
and add a Static Text component to the GUI figure. Next, click on
and add a Pop-up Menu component onto the GUI figure. -
Double click the Static Text component to bring up the Property Inspector. Change the String property to
Testing!!!, and change the Tag property totesting_staticTextas shown in the figure below:

You can also modify the BackgroundColor property if you desire. -
Next, let’s modify the properties of the Pop-up Menu component. First, click on the icon on the String property line as shown below. This allows you to edit the description for each option in the Pop-Up Menu.

After clicking on the icon, you should now see the following window. Fill in the window as shown below:

In addition, I set the Tag property to
popupmenu1, which is the default name. You might want to make sure that its named properly before you move on. -
Here’s what your figure should look like after you add the components and modify them.

-
At this point, you also might want to add some Static Text components to add some description tags to the GUI. You can modify their text by double clicking on the component and changing the String property. It’s not required, but I highly recommend it.

-
Save your GUI wherever you please with your desired filename.
Writing the Code for the GUI
Matlab automatically generates an .m file to go along with the figure that you just put together. The .m file is where we attach the appropriate code to the callback of each component. For the purposes of this tutorial, we are primarily concerned only with the callback functions. You don’t have to worry about any of the other function types.
-
Open up the .m file that was automatically generated when you saved your GUI. In the Matlab editor, click on the
icon, which will bring up a list of the functions within the .m file. Select popupmenu1_Callback.

Add the following code to the function:
%gets the selected option switch get(handles.popupmenu1,'Value') case 1 set(handles.testing_staticText,'FontSize',8); case 2 set(handles.testing_staticText,'FontSize',10); case 3 set(handles.testing_staticText,'FontSize',12); case 4 set(handles.testing_staticText,'FontSize',14); case 5 set(handles.testing_staticText,'FontSize',16); otherwise end
-
Lets quickly go over the code now. The following line of code gets the option that the user selected. Remember that in the visual layout of the GUI, we designated five different font sizes for the Pop-up Menu component, giving us five different options for the Pop-up Menu. So for example, if the user selected a font size of 8 (which was the first option in the Pop-up Menu), then the following line of code would return a value of 1. If the user selected a font size of 10, then the value returned would be 2, and so on.
get(handles.popupmenu1,'Value')
Depending on the option selected, the font of the Static Text component will be adjusted using the following line of code for each case statement:
%where ## is the appropiate fontsize value set(handles.testing_staticText,'FontSize',##);
-
Save your m-file!
Run and Test the GUI
Now that we’ve completed both the visual and code aspects of the GUI, its time to run the GUI to make sure it works.
-
From the m-file editor, you can click on the
icon to save and run the GUI. Alternatively, from the GUIDE editor, you can click on the
to launch the GUI. The following GUI should appear once you click the icon: 
-
Go ahead and try selecting different font sizes. If everything was done correctly, you should see the font size of the sample text change accordingly.
-
And that’s it. Those are the basics of using a Pop-up Menu component. You can explore the other options that the slider has to offer through the Property Inspector.
This is the end of the tutorial.
Source files can be downloaded here.
91 Responses to “Matlab GUI Tutorial - Pop-up Menu”
Leave a Reply
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>


Hi there, one quick question?
why did you add the code to the slider1_Callback instead of popupmenu callback?
Hello Bode,
Thanks for catching the error. It’s supposed to be popupmenu1_Callback! I have edited the page to reflect this.
Quan
Thanks!
Thanks for the tutorial about pop up menu, but I want to ask you one question, how to show the a set of options in pop up menu from one field in table ( database ) , example : I use Ms access.
Thankyou
thanks
Hi Quan Quach
Thanks, it helps me too much
Hi there,
How would i go about changing the actual text for each font selected? i.e. when font 8 is selected from the drop down, the static text box will say “font 8 is called fred”, when font 10 is selected, “font 10 is called bill” etc etc
Thanks
Froggy,
You would change the string property to have it reflect what you want it to say.
See step five of this tutorial. Instead of putting in numbers, put in what you want the menu to say.
This is not my question Quan, I mean the drop down menu stays the same but the static box changes text depeding on what font you select, so when I choose a different font you will get different text or words unique to that font such as font 8 displays fred in the static box, font 10 displays bill in the static box, font 12 displays roger in the static box. However, if you simply change the string properties of the static box (so in this case you have five different texts for each of the five fonts), then how can you link them to the drop down menu?
Try this:
Hey there,
If i have values in the pop-up menu, how do i save whatever the user selects in a variable that will be used to create a graph when i click on a push button in my GUI. Do you have any examples that relates to that?
TQ
Thanks Quan, this has really helped!! : )
Hy Quan and Daniel,
What if I want to plot different value in the same axis according to the pop-up menu?
I already tried to use your code and using plot(_,_) instead of set(), but nothing changed.
Thank you for your help…
I have a question. Can matlab do such a thing like - when you enter a number to “edit text” component, let us say number 10, then it appears 10 new edit boxes, and then you can do lots of stuff with those newly appeared edit boxes? If there is a tutorial on that, i would like to find it.
Hi mini,
that is possible but requires that you use lines of codes to create the GUI components. It’s a little bit more complicated, and I’m sorry to inform you that we haven’t yet covered that here at blinkdagger. I recall Doug over at mathworks covered that issue, you should give it a look. You might have to do some browsing into his older posts.
Quan
thanks
Hi there Quan. I got one question for you.
If I got a pop up menu that contains 2 menu, how do I send those string value to another function. For example:
function filter_popup_Callback(hObject, eventdata, handles)
switch get(handles.filter_popup,’String’)
case ‘Unsharp’
set(handles.linear_pushbutton,’String’,'unsharp’);
case ‘Average’
set(handles.linear_pushbutton,’String’,'average’);
end
function linear_pushbutton_Callback(hObject, eventdata, handles)
I = getimage(handles.axesBefore);
h = fspecial(’sobel’);
I2 = imfilter(I,h);
Let’s say I’ve choosen Unsharp menu from the pop-up, how do I replace the ’sobel’ in the linear_pushbutton to ‘unsharp’?
Thank you
Danny,
The following should work
Well Quan, thank you for that. After I’ve done the modification, MATLAB provides me with this error… Can you help me out with this? Thank you so much. This is the error that comes out at the MATLAB when the GUI is being run.
??? Error using ==> ImageEnhancement(’linear_pushbutton_Callback’,gcbo,[],guidata(gcbo))
Function FSPECIAL expected its first input, TYPE,
to be one of these types:
char
Instead its type was cell.
Oh yea… they gave out this error too… Its from the pop up menu
??? Error using ==> ImageEnhancement(’filter_popup_Callback’,gcbo,[],guidata(gcbo))
SWITCH expression must be a scalar or string constant.
??? Error while evaluating uicontrol Callback
Hey danny,
you’re right, i gave you some faulty code. I didn’t have matlab on the pc so I couldn’t double check my answer. I’ll get back to you on this one.
Quan
Ok Quan
hello Danny,
this code should work. i tested it on matlab!
sorry for the delay
Hi there Quan,
I really appreciate for all those codes that you’ve showed me. It really helped me a lot. Thank you very much.
hola
quiero saber como colacar comandos en el pop up menu es que estoy haciendo un convertidor de unidades, y no se bien como utilizarlo
You are the most awesome online tutor ever…
May god bless you with more knowledge.
Hi
My problem to call popup menu is:
I have created in my gui a pop-up window “Direction” with
3 menues (AP,RL and FH) that must shows the direction of
medical image in 3 direction. When the user chooses it. I
tried to call the function. This pop up menu is not active.
It shows only the first or default image. What can I do to
solve this problem? and I tried to plot the image in case of popup as showen. But I get only deufalt image. my popup button has no function
==================================================
function plot_popupmenu_Callback(hObject, eventdata, handles)
% hObject handle to plot_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,’String’) returns plot_popupmenu contents as cell array
% contents{get(hObject,’Value’)} returns selected item from plot_popupmenu
%##########################################################################
%get the value of the current Pop-up menu selection
%plotType =1, if AP option is chosen
%plotType =2, if FH option is chosen
%plotType =3, if RL option is chosen
velocityDirection = get(handles.plot_popupmenu,’Value’)%get(hObject,’Value’);
%val = get(hObject,’Value’);
str = get(hObject, ‘String’);
switch str{velocityDirection};
case ‘AP’
handles.current_data = handles.phaseImageAP;
case ‘FH’
handles.current_data = handles.phaseImageFH;
case ‘RL’
handles.current_data = handles.phaseImageRL;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
get(handles.plot_popupmenu,’Value’)
axes(handles.axes2);%gives focus to second axes
if velocityDirection ==1
imshow(handles.phaseImageAP,[]);
colormap(gray);
zoom on;
else if velocityDirection == 2
imshow(handles.phaseImageFH,[]);
colormap(gray);
zoom on;
else if
imshow(handles.phaseImageAP,[]);
colormap(gray);
zoom on;
handles.current_data = handles.phaseImageAP;
axes(handles.axes2);%gives focus to second axes
imshow(handles.current_data,[]);
colormap(gray);
zoom on;
end
guidata(hObject,handles)
hi
pleas can you help me to set the data in the pop menu by a vector because all tutorial shown that the dat is defined manualy and can not be edit or set automatically.
Hello,
I need help with something. I have a pop-up menu in my gui and I have added several values that can be selected from the user. I want to be able to take the value selected as a number(eg a 2) and be able to use this in another m-file (my gui’s engine). Any ideas?
Hello Quan,
This tutorial helps me somewhat, but I there is one problem I’m having. Is there an easy way to add new items to the popup menu after the GUI is running.
For example, The GUI starts out with Zero items in the popup menu. The user has the ability to type text in a text box then hit a button to add that text to the popup menu list.
Thanks in advance.
Hi, I have essentially the same question as Sam above: how do we set up the switch cases for a dynamically generated pop-up list, after the GUI is running?
Specifically in my GUI, the user selects a file, which has a variable number of signal recordings, whose names are copied into the pop-up menu; how can I perform actions on those different signals by selecting them from the pop-up menu?
Thanks in advance!
Hi Quan,
I am writing a program to predict deflections of cantilevered and simply supported beams, under either single point, or uniformly distributed loads (UDL).
I wish to use a pop-up menu to give the user a choice of material of the beam (including an option for the user to enter their own value (young’s modulus)), and another to choose the cross-section of the beam.
What i would like to know is how would you put in an equation so that if the user selected, for example a rectangular cross section, the program would know to sub values that the user entered via edittext boxes, into that particular equation, and then take the resulting value and place it in a final equation that would calulate the deflection of the beam.
Hi every body.
I am Vietnameses. I am learning processing image with Matlab. I need help with something:
I had a Axes to display image with name is axes_image. And now , I want setup a pop-up menu with string is colors pink, gray, hsv to processing this image(image in axes_image). I want use function pink, gray, hsv of Matlab to process. But I can’t. Please help me. I write this code but it don’t run.
Val = get(handles.popupmenu1, ‘value’);
Str = get(handles.popupmenu1,’string’);
switch str(val)
case ‘gray’
handles.current_data = handles.x;
case ‘hsv’
handles.current_data = handles.x;
case ‘pink’
handles.current_data = handles.x;
get(handles.popupmenu1,’value’);
axes(handles.axes2);
if Val ==1
imshow(handles.x,[]);
colormap(gray);
else if Val == 2
imshow(handles.x,[]);
colormap(hsv);
else Val == 3;
imshow(handles.x,[]) ;
colormap(pink);
end
Thank you very much!
Using iscell and ischar in Matlab 2007b, my PopUpMenuCallback is returning a character array instead of a cell array when doing get(hObject,’String’).
Instead of using a cell array as you indicated in your code sample from 06 Apr 2008 at 10:40 pm 23 (using the curly brackets), I had to do the following:
function PopUpMenu_Callback(hObject, eventdata, handles)
val = get(hObject,’Value’)
string_list = get(hObject,’String’)
selected_string = string_list(val,1:end)
Has there been a change in Matlab or is there something screwy with my system?
Thank you
I can’t say for sure, but if there is only one string in the string list, then the data type is a “string”. If there are multiple strings in the pop up menu then it would be a “cell”. I don’t believe anything has changed between versions, so I will have to check.
Quan
Between your reply and further reading, it finally dawned on me that depending upon how the strings are set in the popup menu dictates the method used for reading them. see the two example below
using a string vector
function popUpMenu_Callback(hObject, eventdata, handles)
set(hObject,’String’,['one|two|three'])
val = get(hObject,’Value’)
string_list = get(hObject,’String’)
selected_string = string_list(val,1:end)
using a cell array of strings
function popUpMenu_Callback(hObject, eventdata, handles)
set(hObject,’String’,{’one’ ‘two’ ‘three’})
val = get(hObject,’Value’)
string_list = get(hObject,’String’)
selected_string = string_list{val}
that is good to know! thanks pwilson!
hi fine
hello,
I found your tutorials very helpful, but i still have a question:
let’s say i have 2 popup menus. How should i proceed if the options in the second menu depend on the choice in the first menu?
ex: menu1 = 1, 2 or 3
and menu2 = 11, 12 or13 if menu1 = 1
menu2 = 21, 22, 23 or 24 if menu1 = 2
and so on ?
Thanks in advance.
L.
Lauren,
Assuming you have two popupmenus named popupmenu1 and popupmenu2:
Thank you. I’ll try this.
hello
Quan
I also found your tutorials very helpful, but i still have a question:
if my popup contain string for example
c:\fdfd\hjhjh
c:\fd\hg
d:\ah\gh
and i want to do some processing in other function and add new item to popupmenu example
e:\af\aj
how can i do that
thank you
ahmed
ahmed,
You can try the following:
Hope that helps
Quan
Oh thank you Quan
yes it work good
thank you v.much for your help
ahmed
Hi Quan Quach
I have four pop-up menu and one radio button and one push button to control everything. Can you give me a sample code to display output.
Hello Quan Quach,
I would like to ask how would you write a code with a popup menu in which when i select an option from the menu, a desired image would be displayed on the GUI?
For example, i’m doing a project on Plantar images of a foot, if i would to choose region 1 from the popup menu, how would i display an image(found on my hard-drive) on the GUI?
Would really appreciate your help. Thanks.
switch get(handles.popupmenu2,’Value’)
case 1
set(handles.testing_staticText1,’FontSize’,10);
set(handles.testing_staticText1,’String’,'Region 1′);
case 2
set(handles.testing_staticText1,’FontSize’,10);
set(handles.testing_staticText1,’String’,'Region 2′);
case 3
set(handles.testing_staticText1,’FontSize’,10);
set(handles.testing_staticText1,’String’,'Region 5′);
case 4
set(handles.testing_staticText1,’FontSize’,10);
set(handles.testing_staticText1,’String’,'Region 6′);
case 5
set(handles.testing_staticText1,’FontSize’,10);
set(handles.testing_staticText1,’String’,'Region 7′);
otherwise
end
nicksterr
Say I decide to place a set of edit text boxes. I want the user to put numeric values in each box. Then I want to be able to define a matrix from the numbers the user put in the edit text boxes.
example: edit text box 1 tag is changed to x1, text box 2 to x2, and so on.
I want to be able to create a matrix such that x = [x1 x2 x3....]
Any advice?
update…I got this to work…i think.. how would I multiply the two together
w transpose * x ?
so…can someone explain to me why this is returning
net =
14654
the matrices should be a 1×6 times a 6×1…resulting in a 1×1…somethings wrong…
please help!
try converting it into numbers first using str2num
thanks!
hi i want to add a new pop-pup string to an pop-pup but this code erase all the other item and create a new item
set(handles.mypoppup,’string’,'new item’)
please can you people help me to add it not to erase and then create
thanks
Hi..
I want creat a popup menu dat allows me to run different simulink files files on different selection…..that is if i select option “first order” in the popup menu then it should run simulink file named firstorder.mdl and if i select “second order” in popup menu then it should run simulink file named secorder.mdl….. How can i do dat??? Please help…. Thanks in advance..
Hi.. i want to create a dynamic pop-up menu and for each item in menu i have to get a value. how should i do that.
Problem : Like in a liquid system you ‘n’ no. of components . so pop up menu has elements Component 1, Component 2… and so on uptil Component ‘n’. For each component i have to get its respective composition in mole fraction. Also ‘n’ is given at runtime. How can i do this.
Akshayy,
Good question. You’ll have to modify the pop-up menu widget within the code to make it work. Once you know what N is, you can use the following code to modify the pop up menu. I don’t have MATLAB handy, so I can’t confirm if this exact code will work, but hopefully you get the idea!
Quan
Hi Quan
Thnx a lot. It really helped. I was trying strcat but it was not working.
I also have to get compositions for the n-components and 4 that i don’t want to make ‘n’ edit boxes i want 2 control from 1 only. i tried set function 2 reset edit box value to NULL and the ask user to enter but it is not working. Can u plz help.
Hi Quan
Plz tell also how can define ‘n’ cases for the pop-up menu.
Hi
thnx again. but i tried on my own and did it. instead of using switch i just passes around using ->
val=get(hObject,’Value’);
set(handles.pb2,’Visible’,'on’);
set(handles.pb3,’Visible’,'on’);
str=num2str((val));
set(handles.text2,’Visible’,'off’);
set(handles.text2,’String’,str);
guidata(hObject,handles);
pb1 and pb2 are two push buttons. i get val from text2 and then store edit text box value in handles.x(val).
Hi Quan,
I found your website very useful in all matters concering matlab.
I’m relatively new to gui’s in matlab. Just trying to write callbacks for my popupmenu. At the moment this is what i have:
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,’String’) returns popupmenu1 contents as cell array
% contents{get(hObject,’Value’)} returns selected item from popupmenu1
val = get(hObject,’Value’);
switch val
case 1
set(handles.popupmenu1,’Value’,Frequency (Hz))
case 2
set(handles.popupmenu1,’Value’,4)
for i= 1:5
imshow(C);
pause(0.5);
imshow(I);
pause(0.5);
end
case 3
set(handles.popupmenu1,’Value’,8)
case 4
set(handles.popupmenu1,’Value’,16)
end
The problems that i have are
(1) the menu sometimes disappears
(2)
(2) when i select the value 4 it should enter the for loop,
i have already added the strings to the property inspector string tag. and i have added values as well. i.e value 1.0, 2.0, 3.0, 4.0.
Does anyone have any ideas
Cheers
Kartik
Hi,
Thank you very much for the tutorial.
I want to ask that whether it is possible to use popup menu for inputing data file?
If so, how shall I start the programme?
Regards
hi………
thank you very much for the tutorial
i want to design a guide for automatic control system.could you help me about command “callback”.and using in m-file.if you know vietnamese,i can say with you by vietnamese.
cheers
thang
Hey Quan,
Your website is very helpful for someone like me who is absolutely clueless with programming. Thank you very much!!
I have a quick question regarding the popup menu. I am making a program to calculate the metabolism rate of human. I want the users to choose the gender from the popup (male or female) and calculate the rate accordingly. There will be different coefficients depending on the gender (ex: 5 for male, 3 for female). How do I develop the MATLAB code to link the coefficients so it will automatically calculate the rate?
Bests,
Dianna
Dianna,
I’m sure Quan loves hearing those kind words. You should be able to follow the steps from this tutorial to do that, but I’ll show you where it differs:
In step 4 of the first page of this tutorial, instead of filling in the ‘String’ box (from the inspector bar) with numbers, you would put ‘Male’ and ‘Female’ on separate lines. I like having a blank line at the top (3 lines total) so the ‘default’ would show a blank, instead of ‘Male’ in my example.
The 2nd major difference would be in the callback function for the popup menu (step 1 on 2nd page of tutorial)
Each ‘case’ represents the different lines from the ‘String’ box you just created
You can then calculate your value at the end of the callback, or you can associate the calculation in another function in your GUI.
I hope that’s clear,
-Zane
Thanks Zane!
When I include the coefficients to the function, do I include (ex: from the tutorial for beginners) like this?
It does not seem to work. Hope to hear from you soon.
Dianna
Hello Dianna,
Zane pretty much summed it up nicely in his response. If you are planning on keeping your metabolism coefficients constant, then you should just hard code it into the GUI m-file, as Zane did. If you want the user to be able to specify the coefficient, then you would use the edit text box, similar to the tutorial for beginners.
Please take a closer look at what Zane wrote as did a pretty thorough job. Take a look below at the code I modified as well.
Quan
Thanks Quan! I got my program to work.
Hello,
I am creating a GUI program that calculates body mass index (bmi) and i want it to classify the user in a range according to the bmi value. (e.g. if bmi is < 18 — normal, if bmi between 18 and 24 — overweight …) .
any idea how i can do that ?
Thanks !!!!!!!
Elie
Hi Quan,
Am new to this but since am doing some simple work on MATLAB, I found your explanation here more understanding..
I have a pop-up menu with number of list inside it (Say) :
College
University
Estate
Country
Now I am having other GUI created with other information in it.
(say) about college with student strength, programmes, professor strength,when established, propierator,etc…with GUI name as “College_Info”
Now in my pop-up menu when I click College I want this GUI to be called and get pop-up window showing all the information about college…….if i click University, all the information about university,etc..How I would do it….
Else will it be possible to write a programme itself within the pop-up menu under case College and create a pop-up menu…if yes how???Please advice me earliest coz am very in need & got limited time to proceed…
Thanks in advance…would appreciate if you could mail me at ngyltsn@gmail.com
Hi everybody,
I am new to MATLAB and this site has been very helpful! I have a question that seems like basic MATLAB compared to most of the operations I’ve seen on here.
I have a pop up menu and a push button. The pop up menu has 4 different options on it. I want the push button to operate by opening a computer program corrseponding to the item selected on the pop up menu.
For example, Pop up menu has: Minesweeper
Solitaire
Hearts
Pinball
I want whatever is selected to have the game opened when the push button is pressed. (?using system(’cmd’)?) Is this possible on MATLAB? Thank you so much!
Hi!
This is a great tutorial, I just have one question. In step 1 of writing the code for the GUI, is it possible to address the cases by the option the user selects from the pop up menu instead of by the order of the options listed in the string? With the current method, if I wanted to go back and add odd numbers chronologically to the list, I’d have to completely rewrite the switch function. But if there was a way to address the cases by the option itself, then I could just add code for the odd numbers.
I am building DVB-T using Matlab GUI, and I am having problems writing the “Gray Code” callback into it. Can you please help?
[...] GUI Tutorial - Slider MATLAB GUI Tutorial - Pop-up Menu MATLAB GUI Tutorial - Plotting Data to Axes MATLAB GUI Tutorial - Button Types and Button Group [...]
Thanks a lot, i’m new to MATLAB but i learnt more thing from this discussion god bless to all
If anyone know how to convert string to asterics please help me…
Hi,
My GUI runs when i press a pushbutton, however, whenever i choose a different option from the pop-up menu i get the following error message
??? SWITCH expression must be a scalar or string constant.
Error in ==> nontimevaryingODE2>popupmenu1_Callback at 512
switch get(handles.popupmenu1,’String’)
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> nontimevaryingODE2 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
guidemfile>@(hObject,eventdata)nontimevaryingODE2(’popupmenu1_Callback’,hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
it’s not like it will screw up the program but is there a way to fix it so that when i choose the option it doesn’t update immediately and give me the error?
my code is as follows:
Thankss
Dude~!You are awesome and a life savior!!!
Best wishes from Su, New Haven, C.T
Is there any way to extract the string that is selected in the popupmenu without using a switch/case scenario? I have a large popupmenu and want to avoide the tedious coding….just grab whatever string is selected at the time… Thanks!
Tim
how to show pop up menu in axes,.. if choices a program for show pitch,and formant like this…..
case 1
%untuk mencari energy
fs=10000;
[y,fs]=wavread(’aaq.wav’);
subplot(211)
plot(y)
axis([0 length(y) -1.2 1.2])
title(’Sinyal Wicara & Energi Rata-2 setiap Frame’)
ylabel(’Magnitudo Sinyal Wicara’)
y_l=length(y);
jj=floor(length(y)/200);
n1=1; n2=200;
for j=1:jj
for i=n1:n2
x(i)=y(i);
xx =sum(abs(x(i)));
end
xx=xx/200;
for i=n1:n2
x(i)=xx;
end
n1=n1+200;
n2=n2+200;
end
subplot(212)
plot(x);
ylabel(’Energi Setiap Frame’)
case 2
%untuk mencari pitch
T=100;
t=0:1/T:2;
f1=1;
y1=sin(2*pi*t);
subplot(2,1,1)
plot(t,y1)
case 3
%untuk mencari nilai formant
[x,fs]=wavread(’aaq.wav’);
% resample to 10,000Hz (optional)
x=resample(x,10000,fs);
fs=10000;
% plot waveform
frame_1=0.02*fs;
xframe=x(5*frame_1:6*frame_1);
t=(0:length(xframe)-1)/fs; % times of sampling instants
plot(t,xframe);
legend(’1 Frame Waveform’);
ylabel(’Magnitude’)
xlabel(’Time’)
% do fourier transform of windowed signal
Y=fft(xframe.*hamming(length(xframe)));
%plot spectrum of bottom 8000Hz
hz5000=5000*length(Y)/fs;
f=(0:hz5000)*fs/length(Y);
plot(f,20*log10(abs(Y(1:length(f)))+eps));
legend(’Spectrum’);
xlabel(’Frequency (Hz)’);
ylabel(’Magnitude (dB)’);
% get Linear prediction filter
ncoeff=2+fs/1000; % rule of thumb for formant estimation
a=lpc(x,ncoeff);
% plot frequency response
[h,f]=freqz(1,a,512,fs);
plot(f,20*log10(abs(h)+eps));
legend(’LP Filter’);
xlabel(’Frequency (Hz)’);
ylabel(’Gain (dB)’);
% find frequencies by root-solving
r=roots(a); % find roots of polynomial a
r=r(imag(r)>0.01); % only look for roots >0 up to fs/2
ffreq=sort(atan2(imag(r),real(r))*fs/(2*pi));
% convert to Hz and sort
for i=1:length(ffreq)
fprintf(’Formant %d Frequency %.1f\n’,i,ffreq(i));
I have aproblem about popup-menu. In my popup-menu, there are 4 different case. If I select case1 and case3, I have to give two parameters under pupup-menu (I used edit-text for this). For the others, there is only one parameters.
My problem is that transition case1 and case3 to case2 and case4. I want to edit text invisible in case of case2-4. without given any parameters, system is working. I can do edit text invisible for case2-4. Firstly I select case1 and give a parameter for this, but I change my decision and I select case2. In this situation, edit taxt can not be invisible, system give an error.
Above, I try to explain my problem. Sorry, I am a new user for matlab. How can I solve this problem. After giving a parameter in an edit-text, how can I delete the parameter and how can I edtit-text invisible.
Enes.
Thanks for your helping
function myguifcn(arg)
%myguifcn sample switchyard programming example.
persistent mydata
if nargin==0
arg=’initialize’;
end
switch arg
case ‘initialize’
%code that creats the GUI and sets the callbacks
uicontrol(’style’,'pushbutton’,’string’,'apply’,'callback’,'myguifcn apply’)
%in a real GUI other properties must be set also
uicontrol(’style’,'pushbutton’,’string’,'revert’,'callback’,'myguifcn revert’)
%in a real GUI other properties must be set also
uicontrol(’style’,'pushbutton’,’string’,'done’,'callback’,'myguifcn done’)
%in a real GUI other properties must be set also
mydata=%data must be stored in the GUI for callback use,
%most commonly a structure
case ‘apply’
%code for perfoms apply button callback actions
case ‘revert’
%code for perform revert button callback actions
case ‘done’
%code for performs done button callback actions
otherwise
%report error?
end
i am a new user of matlab and i have to learn matlab programming and use it for my project work con u help me please
thanks a lot!
sooooooooooo much easier to find and apply than the matlab central guidelines!
Hi Quan
Many thanks for your efforts…
I have a question:
I used Pop-up menu option to get the value of one parameter. Code is working alright but after selecting the value from the GUI, they always disappear…and then I can not change those values. But in the program that parameter is assigned correct value.
I have written some program….
************************************
function millingmode_gui_Callback(hObject, eventdata, handles)
% hObject handle to millingmode_gui (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,’String’) returns millingmode_gui contents as cell array
% contents{get(hObject,’Value’)} returns selected item from millingmode_gui
%gets the selected option
switch get(handles.millingmode_gui,’Value’)
case 1
set(handles.millingmode_gui,’string’,'1′);
case 2
set(handles.millingmode_gui,’string’,'2′);
case 3
set(handles.millingmode_gui,’string’,'3′);
otherwise
end
guidata(hObject, handles);
********************************************
Then I use the extract the value of “millingmode_gui” in some function called by Push Button…by using…
*******************
millingmode=str2num(get(handles.millingmode_gui,’String’))
**************************
but after selecting the value from GUI, pop menu just disappear….
and I get some warnings from the command window…
****
Warning: popupmenu control requires that Value be an integer within String range
Control will not be rendered until all of its parameter values are valid
************
I am not able to find the mistake..Please help me in this regard
I hope to hear from you soon
Saurabh
I am not able to find it…
Hi Quan
Many thanks for your efforts…
I have a question:
I used Pop-up menu option to get the value of one parameter. Code is working alright but after selecting the value from the GUI, they always disappear…and then I can not change those values. But in the program that parameter is assigned correct value.
I have written some program….
Then I use the extract the value of “millingmode_gui” in some function called by Push Button…by using…
but after selecting the value from GUI, pop menu just disappear….
and I get some warnings from the command window…
****
Warning: popupmenu control requires that Value be an integer within String range
Control will not be rendered until all of its parameter values are valid
************
I am not able to find the mistake..Please help me in this regard
I hope to hear from you soon
Saurabh
Saurabh,
I commented on your other post which has similar error (even though you get 2 different results)
http://blinkdagger.com/matlab/matlab-gui-tutorial-buttons-button-group/#comment-6071
Hi,
I’m trying to create a popup menu with a different text color in each of the list items.
¿Do you have any idea if this is possible?
thank you
I found the answer to the color listbox, so here’s a link in case someone is interested,
http://www.mathworks.de/matlabcentral/newsreader/view_thread/164175
[...] GUI Tutorial - Slider MATLAB GUI Tutorial - Pop-up Menu MATLAB GUI Tutorial - Plotting Data to Axes MATLAB GUI Tutorial - Button Types and Button Group [...]