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:
pop up menu gui

Subject: pop up menu gui

From: Chanpreet

Date: 9 Aug, 2010 13:12:10

Message: 1 of 6

dear all

I am new to matlab gui.
 I have a question. please help me with your suggestions.
I want to save the option selected from pop up menu and want to use it in some other .m file.
I have used save and load comand it is also not working.
my problem looks like this
str = get(hObject,
'String');
val = get(hObject,
'Value');
% Set current data to the selected data set.
switch str{val};
case 'Inner_points'
con = 1;
case 'Inner_radius' % User selects Membrane.
con = 2;
case 'Inner_points_and_radius' % User selects Membrane.
con=3;
case 'Outer_points' % User selects Membrane.
con=4;
case 'Outer_radius' % User selects Membrane.
con=5;
case 'Outer_points_and_radius' % User selects Membrane.
con=6;
case 'Both_inner_and_outer_shape' % User selects Membrane.
con=7;
end
guidata(hObject, handles);
% save -mat con.m con
% load -mat con.m con
  I want to save the con.
if you can help me with this question or if you can tell me some other option, it would be very helpful for me.
thanks in advance for looking at my problem

Subject: pop up menu gui

From: Frédéric Bergeron

Date: 9 Aug, 2010 13:27:05

Message: 2 of 6

"Chanpreet " <c.kaur@tue.nl> wrote in message <i3oura$klh$1@fred.mathworks.com>...
> dear all
>
> I am new to matlab gui.
> I have a question. please help me with your suggestions.
> I want to save the option selected from pop up menu and want to use it in some other .m file.
> I have used save and load comand it is also not working.
> my problem looks like this
> str = get(hObject,
> 'String');
> val = get(hObject,
> 'Value');
> % Set current data to the selected data set.
> switch str{val};
> case 'Inner_points'
> con = 1;
> case 'Inner_radius' % User selects Membrane.
> con = 2;
> case 'Inner_points_and_radius' % User selects Membrane.
> con=3;
> case 'Outer_points' % User selects Membrane.
> con=4;
> case 'Outer_radius' % User selects Membrane.
> con=5;
> case 'Outer_points_and_radius' % User selects Membrane.
> con=6;
> case 'Both_inner_and_outer_shape' % User selects Membrane.
> con=7;
> end
> guidata(hObject, handles);
> % save -mat con.m con
> % load -mat con.m con
> I want to save the con.
> if you can help me with this question or if you can tell me some other option, it would be very helpful for me.
> thanks in advance for looking at my problem

Hey,

I suggest you not to save this info but to get it directly from your other m-file, the one that is currently loading the info. That way, no new file are created, so it's a step less to do.

To do that, you'll have to have the handle of your popupmenu. If the "other m-file" is the callback function of the popupmenu, you can use gco, but if it isn't, you'll have to save your handles at the end of your main fonction. To do that, I suggest you to use a combinaison of guihandles and guidata, which are working fine for me.

Good luck!
Fred

Subject: pop up menu gui

From: Chanpreet

Date: 10 Aug, 2010 09:29:07

Message: 3 of 6

hello Fred,
thank you very much for your suggestion.
i have used handles for the pop up menu, but the problem is that when i am calling the con value i am not getting it. either i am not using it in the right way or there is some other problem.
 if you can elaborate it more for me . it would be great

Subject: pop up menu gui

From: ImageAnalyst

Date: 10 Aug, 2010 13:46:25

Message: 4 of 6

Try just using the value of the selected index in the switch/case
statement. Or maybe try using strcmpi() or findstr() or strfind() in
your case statements instead of testing the string value directly.

Subject: pop up menu gui

From: Stacy Ross

Date: 18 Aug, 2010 14:23:06

Message: 5 of 6

"Chanpreet " <c.kaur@tue.nl> wrote in message <i3oura$klh$1@fred.mathworks.com>...
> dear all
>
> I am new to matlab gui.
> I have a question. please help me with your suggestions.
> I want to save the option selected from pop up menu and want to use it in some other .m file.
> I have used save and load comand it is also not working.
> my problem looks like this
> str = get(hObject,
> 'String');
> val = get(hObject,
> 'Value');
> % Set current data to the selected data set.
> switch str{val};
> case 'Inner_points'
> con = 1;
> case 'Inner_radius' % User selects Membrane.
> con = 2;
> case 'Inner_points_and_radius' % User selects Membrane.
> con=3;
> case 'Outer_points' % User selects Membrane.
> con=4;
> case 'Outer_radius' % User selects Membrane.
> con=5;
> case 'Outer_points_and_radius' % User selects Membrane.
> con=6;
> case 'Both_inner_and_outer_shape' % User selects Membrane.
> con=7;
> end
> guidata(hObject, handles);
> % save -mat con.m con
> % load -mat con.m con
> I want to save the con.
> if you can help me with this question or if you can tell me some other option, it would be very helpful for me.
> thanks in advance for looking at my problem



I use global variables to send information from one .m to another.

Example:


your First .m

global abc

insert your code:

abc.con=con;


Your second .m
global abc
con=abc.con;

your function code

Best,
Stacy

Subject: pop up menu gui

From: Sean

Date: 18 Aug, 2010 15:11:18

Message: 6 of 6

"Chanpreet " <c.kaur@tue.nl> wrote in message <i3r653$rft$1@fred.mathworks.com>...
> hello Fred,
> thank you very much for your suggestion.
> i have used handles for the pop up menu, but the problem is that when i am calling the con value i am not getting it. either i am not using it in the right way or there is some other problem.
> if you can elaborate it more for me . it would be great

look at:
help getappdata
help setappdata

These two are made specifically for passing handles. I would use these over globals as another user has suggested.

Tags for 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