From: Luna Moon on 8 Jun 2010 12:09 Hi all, I have many strings with the following format: "abc12" "bcde2" "cef333" All of them have letters on the left and numbers on the right. I would like to obtain all these numbers on the right side of the strings, MyNumbers=ObtainTheNumberSuffix(InputStrings) ObtainTheNumberSuffix('abc12') = '12' or 12 ObtainTheNumberSuffix('bcde2') = '2' or 2. How to do that? thankx
From: Wiater on 8 Jun 2010 12:29 > Hi all, > MyNumbers=ObtainTheNumberSuffix(InputStrings) > > ObtainTheNumberSuffix('abc12') = '12' or 12 > > ObtainTheNumberSuffix('bcde2') = '2' or 2. > > How to do that? > > thankx > try this: for i=1:length(string) if isscalar(str2num(string(i))) number=str2num(string(i:end)); break end end
From: Alan B on 8 Jun 2010 12:46 Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <bd7f8a8d-eb1f-4d64-aca2-b5cea3cec4ce(a)d37g2000yqm.googlegroups.com>... > Hi all, > > I have many strings with the following format: > > "abc12" > > "bcde2" > > "cef333" > > All of them have letters on the left and numbers on the right. > > I would like to obtain all these numbers on the right side of the > strings, > > MyNumbers=ObtainTheNumberSuffix(InputStrings) > > ObtainTheNumberSuffix('abc12') = '12' or 12 > > ObtainTheNumberSuffix('bcde2') = '2' or 2. > > How to do that? > > thankx One way: s(s<='9')
From: Luna Moon on 8 Jun 2010 13:43 On Jun 8, 12:46 pm, "Alan B" <monguin61...(a)OVETHIS.yahoo.com> wrote: > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <bd7f8a8d-eb1f-4d64-aca2-b5cea3cec...(a)d37g2000yqm.googlegroups.com>... > > Hi all, > > > I have many strings with the following format: > > > "abc12" > > > "bcde2" > > > "cef333" > > > All of them have letters on the left and numbers on the right. > > > I would like to obtain all these numbers on the right side of the > > strings, > > > MyNumbers=ObtainTheNumberSuffix(InputStrings) > > > ObtainTheNumberSuffix('abc12') = '12' or 12 > > > ObtainTheNumberSuffix('bcde2') = '2' or 2. > > > How to do that? > > > thankx > > One way: > s(s<='9')- Hide quoted text - > > - Show quoted text - very good idea. Thank you so much!
From: Luna Moon on 8 Jun 2010 13:43 On Jun 8, 12:29 pm, "Wiater" <wia...(a)poczta.onet.pl> wrote: > > Hi all, > > MyNumbers=ObtainTheNumberSuffix(InputStrings) > > > ObtainTheNumberSuffix('abc12') = '12' or 12 > > > ObtainTheNumberSuffix('bcde2') = '2' or 2. > > > How to do that? > > > thankx > > try this: > > for i=1:length(string) > if isscalar(str2num(string(i))) > number=str2num(string(i:end)); > break > end > end sorry we don't like "for" thank you anyway!
|
Pages: 1 Prev: How to make my code faster? Hate my stupid coding! Next: bar plot basic problem |