4.0

4.0 | 5 ratings Rate this file 80 downloads (last 30 days) File Size: 2.9 KB File ID: #4615

Split delimiter separated strings into a matrix

by Gie Spaepen

 

12 Mar 2004 (Updated 16 Mar 2004)

No BSD License  

Function to split a delimiter separated string into a matrix of doubles.

Download Now | Watch this File

File Information
Description

Function: outmatrix = strsplit(inpstr[,delimiter])

Input:
inpstring, this is the input string which is a delimiter separated string: 345.56,376.5,4334.34 .
delimiter, optional if not given, ',' is taken.
outmatrix: if all values in inputstring are numerical a double array is given otherwise a cell array.

Acknowledgements
This submission has inspired the following:
rsplit
MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
15 Mar 2004 Michael Robbins

I could be wrong, but I think there is a much better, vectorized, solution available on CSSM

15 Mar 2004 Urs Schwarz (us)

strread will do the same - and - it comes with more options

25 Mar 2008 Joel Sander

It was simple and did exactly as advertised.

29 Aug 2008 Nikola Toljic

Great. Thanks.

07 Jul 2009 Siamak Faridani  
24 Sep 2009 jjcai Cai

One of the problems of this function is that it does not work with delimiter '\t'.

One of many solutions by
u...@neurol.unizh.ch (I found from google groups) is as follows:

>> s=sprintf('one\ttwo three\tfour');
>> r=regexp(s,'\t','split')

24 Sep 2009 jjcai Cai  
27 Oct 2009 Flurin Honegger

The handling of the "no delimiter in string .." case is not necessary and results in an inconsistent interface that results in unnecessary checking of return values.
I would leave out the check on "size(idx) == 0" and initialize
tempsplit as follows tempsplit = {inpstr};

Thank you for posting this routine that in contrast to regexp(s,'\t','split') (since R2007b) works also on older Matlab versions.

Please login to add a comment or rating.
Updates
16 Mar 2004

The inputstring could only consist of numerical values, now it can contain strings as well.

Tag Activity for this File
Tag Applied By Date/Time
strings Gie Spaepen 22 Oct 2008 07:16:11
split string Gie Spaepen 22 Oct 2008 07:16:11
delimiter Gie Spaepen 22 Oct 2008 07:16:11
separated Gie Spaepen 22 Oct 2008 07:16:11
utilities Gie Spaepen 22 Oct 2008 07:16:11
string manipulation Gie Spaepen 22 Oct 2008 07:16:11
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com