Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Extract values from a string

$
0
0
On 12/15/2012 12:52 PM, dpb wrote:
> On 12/15/2012 11:20 AM, Tiger wrote:
>> Hi folks,
>>
>> Suppose the following:
>> a = '1.4.6.5.11'; % String
>>
>> I want to be able to extract those numbers, in variable 'a',
>> individually and assign them into another variable 'b', such b = {1, 4,
>> 6, 5, 11};
> ...
>
> b=sscanf(a,'%d.');

 >> a = '1.4.6.5.11';
 >> sscanf(a,'%d.')
ans =
      1
      4
      6
      5
     11

BTW, the much ballyhoo'ed textscan() barfs on this one...

 >> textscan(a,'%d.')
ans =
     [3x1 int32]
 >> ans{:}
ans =
            1
            7
           11
 >> >> textscan(a,'%d','delimiter','.')
ans =
     [3x1 int32]
 >> ans{:}
ans =
            1
            7
           11
 >>

It's not at all clear to me where it invented the '7' from and why it
failed so miserably...

Comments, TMW??? Bug or some intended behavior?

--

Viewing all articles
Browse latest Browse all 19628

Latest Images

Trending Articles



Latest Images