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

  • Follow


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
0
Reply M 3/20/2010 10:08:02 PM

"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
0
Reply us 3/20/2010 10:23:03 PM


"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
0
Reply M 3/20/2010 10:32:04 PM

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?
0
Reply Walter 3/20/2010 11:22:50 PM

> 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.
0
Reply M 3/20/2010 11:44:04 PM

"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
0
Reply us 3/20/2010 11:58:04 PM

> > 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.
0
Reply M 3/21/2010 12:06:03 AM

"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
0
Reply us 3/21/2010 12:17:04 AM

"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
0
Reply M 3/21/2010 12:29:06 AM

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'});
0
Reply Walter 3/21/2010 1:23:19 AM

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?
0
Reply M 3/21/2010 1:50:04 AM

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.
0
Reply Walter 3/21/2010 2:07:36 AM

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'});
0
Reply Walter 3/21/2010 2:17:01 AM

"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
0
Reply us 3/21/2010 11:46:03 AM

13 Replies
221 Views

(page loaded in 0.117 seconds)

Similiar Articles:


















7/10/2012 5:55:30 PM


Reply: