Search All of the Math Forum:

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

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

Topic: Use part of a cell/string
Replies: 7   Last Post: Feb 19, 2013 4:26 PM

 Messages: [ Previous | Next ]
 dpb Posts: 9,850 Registered: 6/7/07
Re: Use part of a cell/string
Posted: Feb 19, 2013 9:55 AM

On 2/17/2013 7:50 PM, Claudia wrote:
> Thanks Maarten, exactly what I was just looking for.
>
> "Maarten" wrote in message <hj79am\$grp\$1@fred.mathworks.com>...

>> I got it!
>> I'll put it up here, for those who might wonder how it's done.
>>
>> if the 'L_500' is stored in d(1,3) you do it as follows:
>> a = char(d(1,3))
>> b = str2num(a(3:end))
>> now b is a double value.

...

If the character substring is constant, one alternative--

>> c
c =
'L_200'
'L_500'
>> str2num(char(strrep(c,'L_','')))
ans =
200
500
>>

or, you can avoid the cast to char() (and the hidden evalc() calls) by

>> str2double(strrep(c,'L_',''))
ans =
200
500
>>

--

Date Subject Author
1/20/10 Justin A
1/20/10 Jan Simon
1/20/10 Justin A
1/20/10 Justin A
1/20/10 ngreco32@gmail.com
2/19/13 dpb
2/19/13 dpb