Thread Subject: split function in matlab?

Subject: split function in matlab?

From: Arthur Zheng

Date: 13 Jul, 2009 15:28:04

Message: 1 of 4

Does matlab have something like a split function to split a string as follows into 2 numbers?

For example, the string may be str = '1..1419', and i want num1=1, num2=1419
or the string may be str = '15455..15997' and the resulting num1 = 15455, num2=15997

Subject: split function in matlab?

From: Jos

Date: 13 Jul, 2009 15:35:19

Message: 2 of 4

"Arthur Zheng" <hzheng7@gatech.edu> wrote in message <h3fjq4$ftg$1@fred.mathworks.com>...
> Does matlab have something like a split function to split a string as follows into 2 numbers?
>
> For example, the string may be str = '1..1419', and i want num1=1, num2=1419
> or the string may be str = '15455..15997' and the resulting num1 = 15455, num2=15997

help STRREAD

str = '15455..15997'
N = strread(str,'%n','delimiter','.')

Jos

Subject: split function in matlab?

From: Jan Simon

Date: 13 Jul, 2009 16:09:03

Message: 3 of 4

Dear Arthur Zheng!

> Does matlab have something like a split function to split a string as follows into 2 numbers?
>
> For example, the string may be str = '1..1419', and i want num1=1, num2=1419
> or the string may be str = '15455..15997' and the resulting num1 = 15455, num2=15997

[Num1, Num2] = strtok('15455..15997', '.');
Num2(findstr(Num2, '.')) = [];

Nevertheless, this is not compact. If FINDSTR is called at all, it can be used to find the delimiter directly:
  Str = '15455..15997';
  Ind = findstr(Str, '..');
  Num1 = Str(1:Ind-1);
  Num2 = Str(Ind+2:end);
This method has the advantage, that it is not confused by a single dot.

Good luck, Jan

Subject: split function in matlab?

From: us

Date: 13 Jul, 2009 16:17:01

Message: 4 of 4

"Arthur Zheng" <hzheng7@gatech.edu> wrote in message <h3fjq4$ftg$1@fred.mathworks.com>...
> Does matlab have something like a split function to split a string as follows into 2 numbers?
>
> For example, the string may be str = '1..1419', and i want num1=1, num2=1419
> or the string may be str = '15455..15997' and the resulting num1 = 15455, num2=15997

a hint:

     help strread;
     help sscanf;
     help regexp; % <- look at the SPLIT option...

us

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
reference us 13 Jul, 2009 12:19:07
split string in... Arthur Zheng 13 Jul, 2009 11:29:03
rssFeed for this Thread

Contact us at files@mathworks.com