The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: assign a number to a string
Replies: 2   Last Post: Dec 14, 2012 9:52 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 55
Registered: 12/11/12
Re: assign a number to a string
Posted: Dec 14, 2012 6:56 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

W dniu 2012-12-14 12:40, Saad pisze:
> Dear all,
> I have a list of string:
> txt={'BBB3', 'BBB2', 'BBB1', 'A3', 'A2', 'A1','AA3','AA2','AA1'};
> i would like to assign a value to each string. For instance,
> Here is my code
> for i=1:length(txt)
> if isequal(txt{'i'},'BBB3')

Why you use quotation marks?

'i' is character i, and it is equal 105.
105-th cell of txt is not equal 'BBB3' :)

if isequal(txt{i},'BBB3')

BTW, have you heard about switch-case expression?

for i=1:length(txt)
switch( txt{i} )
case 'BBB2'
txt{i} = 11
case 'BBB1'
txt {i} = 12


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.