Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
what's the equivalent of substring function in Matlab?

Subject: what's the equivalent of substring function in Matlab?

From: Raymond

Date: 4 Mar, 2006 21:29:26

Message: 1 of 2

Simple question:

I have a string like this 'blah blah [123] more blah 586 aavf', and I want
to extract the number that's enclosed in '[' and ']'. I thought I can use
findstr() to locate the position of '[' amd ']', then I use a substring
function to get 123, but I can't find substring function in Matlab. Any
thoughts?

tline = 'blah blah [123] more blah 586 aavf';
ileft = findstr('[', tline);
iright = findstr(']',tline);
% now what the substring function that I can get something like
substring(tt, ileft, iright)?

thanks

Subject: what's the equivalent of substring function in Matlab?

From: Lee Barker

Date: 5 Mar, 2006 01:01:52

Message: 2 of 2

How about:

tline = 'blah blah [123] more blah 586 aavf';
ileft = findstr('[', tline);
iright = findstr(']',tline);
str2 = tline(ileft:iright)

:)

Raymond wrote:
>
>
> Simple question:
>
> I have a string like this 'blah blah [123] more blah 586 aavf', and
> I want
> to extract the number that's enclosed in '[' and ']'. I thought I
> can use
> findstr() to locate the position of '[' amd ']', then I use a
> substring
> function to get 123, but I can't find substring function in Matlab.
> Any
> thoughts?
>
> tline = 'blah blah [123] more blah 586 aavf';
> ileft = findstr('[', tline);
> iright = findstr(']',tline);
> % now what the substring function that I can get something like
> substring(tt, ileft, iright)?
>
> thanks
>
>
>

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us