[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: String Index
From: |
Thomas D. Dean |
Subject: |
Re: String Index |
Date: |
Mon, 27 Jun 2016 08:43:40 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 |
On 06/26/2016 09:56 PM, PhilipNienhuis wrote:
Thomas D. Dean-2 wrote
I have a string, 87 characters. containing pairs of parens enclosing
characters. The number of chars enclosed is not constant. There are 2
to 5 pairs of parens. How do I construct the index to vectorize this?
> n=numel(str)
n = 87
> lp = [1:n](str == "(");
> rp = [1:n](str == ")");
> ## check to see if parens paired and lp < rp
> [lp', rp']
ans =
38 47
54 57
66 73
85 87
I want to extract values from str using lp and rp
> [ str(lp(1):rp(1));
> str(lp(2):rp(2));
> str(lp(3):rp(3));
> str(lp(4):rp(4)) ]
ans =
(10^20 kg)
(km)
(kg/m^3)
(1)
Read up on regexp()
I played with regexp() some, but, could not find a pattern that matched
just the characters within the parens.
> str
> str = "_units_ (10^15 kg) (km) (kg/m^3) "
> [s, e, te, m, t, nm, sp] = regexp(str,"\(...\){3,5}");m
> m
m =
{
[1,1] = _units_
[1,2] = (10^15 kg)
[1,3] = (km)
[1,4] = (kg/m^3)
}
is close, but, still needs some parsing. Most likely not better than
using strtok.
Tom Dean