Thread Subject: Please help.... Convert text to number in pop up menu

Subject: Please help.... Convert text to number in pop up menu

From: M

Date: 20 Mar, 2010 22:08:02

Message: 1 of 14

I have a pop up menu that only has numbers to select but now i want one which has text. So how do i change this 'text' to a number to insert into my simulink model.

The code used for number pop up menu is:

allvalues = get(handles.popupmenu2,'String');
choiceidx = get(handles.popupmenu2,'Value');

if iscell(allvalues)
   choicestr = allvalues{choiceidx};
else
   choicestr = allvalues(choiceidx,:);
end
choice = str2double(choicestr);
set_param('mymodel/Lockup','Value',choicestr);

thanks

Subject: Please help.... Convert text to number in pop up menu

From: us

Date: 20 Mar, 2010 22:23:03

Message: 2 of 14

"M " <mattyirwinasdasd@aol.com> wrote in message <ho3h02$pjq$1@fred.mathworks.com>...
> I have a pop up menu that only has numbers to select but now i want one which has text. So how do i change this 'text' to a number to insert into my simulink model.

> choice = str2double(choicestr);

well... CHOICE is a number; what's wrong with it(?)...

us

Subject: Please help.... Convert text to number in pop up menu

From: M

Date: 20 Mar, 2010 22:32:04

Message: 3 of 14

"us " <us@neurol.unizh.ch> wrote in message <ho3hs7$8fm$1@fred.mathworks.com>...
> "M " <mattyirwinasdasd@aol.com> wrote in message <ho3h02$pjq$1@fred.mathworks.com>...
> > I have a pop up menu that only has numbers to select but now i want one which has text. So how do i change this 'text' to a number to insert into my simulink model.
>
> > choice = str2double(choicestr);
>
> well... CHOICE is a number; what's wrong with it(?)...
>
> us

i want the pop up menu to be text. the text means a number which is then inputted to my model. Its not like the above code where there were numbers in the pop up menu

Subject: Please help.... Convert text to number in pop up menu

From: Walter Roberson

Date: 20 Mar, 2010 23:22:50

Message: 4 of 14

M wrote:
> "us " <us@neurol.unizh.ch> wrote in message
> <ho3hs7$8fm$1@fred.mathworks.com>...
>> "M " <mattyirwinasdasd@aol.com> wrote in message
>> <ho3h02$pjq$1@fred.mathworks.com>...
>> > I have a pop up menu that only has numbers to select but now i want
>> one which has text. So how do i change this 'text' to a number to
>> insert into my simulink model.
>>
>> > choice = str2double(choicestr);
>>
>> well... CHOICE is a number; what's wrong with it(?)...

> i want the pop up menu to be text. the text means a number which is then
> inputted to my model. Its not like the above code where there were
> numbers in the pop up menu

I've lost track of what you are trying to say.

Are you trying to say that the text in a pop-up entry might be a
variable name or formula, and you want to have that text evaluated and
set the parameter to the resulting value? Or nearly the same as that,
but the parameter should be set to the text representation of the
resulting number?

Subject: Please help.... Convert text to number in pop up menu

From: M

Date: 20 Mar, 2010 23:44:04

Message: 5 of 14


> I've lost track of what you are trying to say.
>
> Are you trying to say that the text in a pop-up entry might be a
> variable name or formula, and you want to have that text evaluated and
> set the parameter to the resulting value? Or nearly the same as that,
> but the parameter should be set to the text representation of the
> resulting number?

The text in the pop up menu is a fixed number value. for example if i had a pop up menu with 5 people names on it and i selected a name. when i ran the model it would load their age into it the simulink model.

Subject: Please help.... Convert text to number in pop up menu

From: us

Date: 20 Mar, 2010 23:58:04

Message: 6 of 14

"M " <mattyirwinasdasd@aol.com> wrote in message <ho3mk4$e88$1@fred.mathworks.com>...
>
> > I've lost track of what you are trying to say.
> >
> > Are you trying to say that the text in a pop-up entry might be a
> > variable name or formula, and you want to have that text evaluated and
> > set the parameter to the resulting value? Or nearly the same as that,
> > but the parameter should be set to the text representation of the
> > resulting number?
>
> The text in the pop up menu is a fixed number value. for example if i had a pop up menu with 5 people names on it and i selected a name. when i ran the model it would load their age into it the simulink model.

this is entirely confusing...
can you eventually come up with a frugal, intelligible example rather than a thousand unstructured words...

us

Subject: Please help.... Convert text to number in pop up menu

From: M

Date: 21 Mar, 2010 00:06:03

Message: 7 of 14

> > Are you trying to say that the text in a pop-up entry might be a
> > variable name or formula, and you want to have that text evaluated and
> > set the parameter to the resulting value? Or nearly the same as that,
> > but the parameter should be set to the text representation of the
> > resulting number?

you are correct, this is what i am looking for.

Subject: Please help.... Convert text to number in pop up menu

From: us

Date: 21 Mar, 2010 00:17:04

Message: 8 of 14

"M " <mattyirwinasdasd@aol.com> wrote in message <ho3ntb$307$1@fred.mathworks.com>...
> > > Are you trying to say that the text in a pop-up entry might be a
> > > variable name or formula, and you want to have that text evaluated and
> > > set the parameter to the resulting value? Or nearly the same as that,
> > > but the parameter should be set to the text representation of the
> > > resulting number?
>
> you are correct, this is what i am looking for.

huh(!)...
you're getting more confusing by the minute...
in your last reply to the very same question, you said
...
The text in the pop up menu is a fixed number value. for example if i had a pop up menu with 5 people names on it and i selected a name. when i ran the model it would load their age into it the simulink model.
...
this time, your answer is completely(to say the least!) different...
your behavior is tedious; can you make up your mind...

us

Subject: Please help.... Convert text to number in pop up menu

From: M

Date: 21 Mar, 2010 00:29:06

Message: 9 of 14

"us " <us@neurol.unizh.ch> wrote in message <ho3oi0$e9o$1@fred.mathworks.com>...
> "M " <mattyirwinasdasd@aol.com> wrote in message <ho3ntb$307$1@fred.mathworks.com>...
> > > > Are you trying to say that the text in a pop-up entry might be a
> > > > variable name or formula, and you want to have that text evaluated and
> > > > set the parameter to the resulting value? Or nearly the same as that,
> > > > but the parameter should be set to the text representation of the
> > > > resulting number?
> >
> > you are correct, this is what i am looking for.
>
> huh(!)...
> you're getting more confusing by the minute...
> in your last reply to the very same question, you said
> ...
> The text in the pop up menu is a fixed number value. for example if i had a pop up menu with 5 people names on it and i selected a name. when i ran the model it would load their age into it the simulink model.
> ...
> this time, your answer is completely(to say the least!) different...
> your behavior is tedious; can you make up your mind...
>
> us

my behaviour is tedious! are you drunk. sort it out
It is not 'completely' different. It is saying....the TEXT in the pop up menu is EQUIVALENT to a number value which is what walter was describing

Subject: Please help.... Convert text to number in pop up menu

From: Walter Roberson

Date: 21 Mar, 2010 01:23:19

Message: 10 of 14

M wrote:
>
>> I've lost track of what you are trying to say.
>>
>> Are you trying to say that the text in a pop-up entry might be a
>> variable name or formula, and you want to have that text evaluated and
>> set the parameter to the resulting value? Or nearly the same as that,
>> but the parameter should be set to the text representation of the
>> resulting number?
>
> The text in the pop up menu is a fixed number value. for example if i
> had a pop up menu with 5 people names on it and i selected a name. when
> i ran the model it would load their age into it the simulink model.

function generalized_popup_callback( src, evt, valuelist, paramname )
   set_param( paramname, valuelist{get(src, 'Value')} );
end

namelist = {'Frank', 'Sam', 'Linda'};
agelist = {35 42 29};
birthplacelist = {'Kyoto', 'Windsor', 'Brisbane'};

uicontrol( 'Style', 'popup', 'String', namelist, ...
  'Callback', {@generalized_popup_callback, agelist, 'mymodel/age'});

uicontrol( 'Style', 'popup', 'String', namelist, ...
  'Callback', {@generalized_popup_callback, birthplacelist,
'mymodel/birthplace'});

Subject: Please help.... Convert text to number in pop up menu

From: M

Date: 21 Mar, 2010 01:50:04

Message: 11 of 14

Walter Roberson <roberson@hushmail.com> wrote in message <ho3se8$hj3$1@canopus.cc.umanitoba.ca>...
> M wrote:
> >
> >> I've lost track of what you are trying to say.
> >>
> >> Are you trying to say that the text in a pop-up entry might be a
> >> variable name or formula, and you want to have that text evaluated and
> >> set the parameter to the resulting value? Or nearly the same as that,
> >> but the parameter should be set to the text representation of the
> >> resulting number?
> >
> > The text in the pop up menu is a fixed number value. for example if i
> > had a pop up menu with 5 people names on it and i selected a name. when
> > i ran the model it would load their age into it the simulink model.
>
> function generalized_popup_callback( src, evt, valuelist, paramname )
> set_param( paramname, valuelist{get(src, 'Value')} );
> end
>
> namelist = {'Frank', 'Sam', 'Linda'};
> agelist = {35 42 29};
> birthplacelist = {'Kyoto', 'Windsor', 'Brisbane'};
>
> uicontrol( 'Style', 'popup', 'String', namelist, ...
> 'Callback', {@generalized_popup_callback, agelist, 'mymodel/age'});
>
> uicontrol( 'Style', 'popup', 'String', namelist, ...
> 'Callback', {@generalized_popup_callback, birthplacelist,
> 'mymodel/birthplace'});

Walter, im not quite sure if you know what i mean. sorry if it has been unclear.
I have a pop up menu which when you click on the arrow it has the list of text (lets say names) that i inputted in the string of the pop up menu.
Now what i want to happen is when this text (a name) is slected from the list and run the GUI it changes this text to a number value i have assigned to it.
What i want to know is how do i assign this text a number?

Subject: Please help.... Convert text to number in pop up menu

From: Walter Roberson

Date: 21 Mar, 2010 02:07:36

Message: 12 of 14

M wrote:
> "us " <us@neurol.unizh.ch> wrote in message
> <ho3oi0$e9o$1@fred.mathworks.com>...

>> this time, your answer is completely(to say the least!) different...
>> your behavior is tedious; can you make up your mind...

> my behaviour is tedious! are you drunk. sort it out

M, the only reason *I* was able to figure out what you might mean is
that I'm an obsessive paranoid, turning words around and around and
around in my head to try to figure out what people _really_ mean. And
even -I- nearly dropped out of the conversation because you were being
fairly incomprehensible. If I'd been asked to go out shopping or do some
cleaning or what-ever instead of having the afternoon with nothing
better to do, then you wouldn't have heard back from me.

If you want answers from people, you have to find better and more
consistent ways to express yourself. It doesn't even have to be in
English, but if it is not in English, the number of readers who will be
able to understand what you write will drop considerably.

Subject: Please help.... Convert text to number in pop up menu

From: Walter Roberson

Date: 21 Mar, 2010 02:17:01

Message: 13 of 14

M wrote:

> Walter, im not quite sure if you know what i mean. sorry if it has been
> unclear.
> I have a pop up menu which when you click on the arrow it has the list
> of text (lets say names) that i inputted in the string of the pop up menu.
> Now what i want to happen is when this text (a name) is slected from the
> list and run the GUI it changes this text to a number value i have
> assigned to it.
> What i want to know is how do i assign this text a number?

Well, if you insist... but I think you have not understood the power and
flexibility of the generalized callback I suggested.


function generalized_popup_callback( src, evt, valuelist, paramname )
    set_param( paramname, valuelist{get(src, 'Value')} );
end

namelist = {'Frank', 'Sam', 'Linda'};
Frank = 35;
Sam = 42;
Linda = 29;

agelist = {Frank Sam Linda};

uicontrol( 'Style', 'popup', 'String', namelist, ...
    'Callback', {@generalized_popup_callback, agelist, 'mymodel/age'});

Subject: Please help.... Convert text to number in pop up menu

From: us

Date: 21 Mar, 2010 11:46:03

Message: 14 of 14

"M " <mattyirwinasdasd@aol.com> wrote in message <ho3p8i$18d$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <ho3oi0$e9o$1@fred.mathworks.com>...
> > "M " <mattyirwinasdasd@aol.com> wrote in message <ho3ntb$307$1@fred.mathworks.com>...
> > > > > Are you trying to say that the text in a pop-up entry might be a
> > > > > variable name or formula, and you want to have that text evaluated and
> > > > > set the parameter to the resulting value? Or nearly the same as that,
> > > > > but the parameter should be set to the text representation of the
> > > > > resulting number?
> > >
> > > you are correct, this is what i am looking for.
> >
> > huh(!)...
> > you're getting more confusing by the minute...
> > in your last reply to the very same question, you said
> > ...
> > The text in the pop up menu is a fixed number value. for example if i had a pop up menu with 5 people names on it and i selected a name. when i ran the model it would load their age into it the simulink model.
> > ...
> > this time, your answer is completely(to say the least!) different...
> > your behavior is tedious; can you make up your mind...
> >
> > us
>
> my behaviour is tedious! are you drunk. sort it out
> It is not 'completely' different. It is saying....the TEXT in the pop up menu is EQUIVALENT to a number value which is what walter was describing

well...
let me just add this before leaving your thread for good:
your behavior is not boding well for a successful future here at CSSM...

firstly, i am not drunk...
second, it is YOU who has to sort things out before wasting CSSMers time...

us

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
scolding M 20 Mar, 2010 20:41:54
scolding us 20 Mar, 2010 20:19:06
rssFeed for this Thread

Contact us at files@mathworks.com