View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Split delimiter separated strings into a matrix

3.8 | 6 ratings Rate this file 10 Downloads (last 30 days) File Size: 2.05 KB File ID: #4615 Version: 1.0

Split delimiter separated strings into a matrix


Gie Spaepen (view profile)


12 Mar 2004 (Updated )

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

| Watch this File

File Information

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

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.


This file inspired Latexfigure and Rsplit.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
05 Feb 2011 Gie Spaepen

Gie Spaepen (view profile)

Thanks for all the comments and downloads. I left my lab for a while now but I will implement your suggestions and make a new release of this script.

Comment only
10 Oct 2010 Matthias Pospiech

This code has a bug for delimiters longer than 1 char. You need to change this lines to :

strtpos = idx(i-1) + sizedelimiter;
tempsplit(i+1) = {inpstr(idx(i)+ sizedelimiter : endpos)};

@Schwarz: if strread does the same, and probably textscan too, why does matlab not provide the necessesary documentation and examples ?

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.

24 Sep 2009 jjcai Cai

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 (I found from google groups) is as follows:

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

Comment only
07 Jul 2009 Siamak Faridani

Siamak Faridani (view profile)

29 Aug 2008 Nikola Toljic

Great. Thanks.

25 Mar 2008 Joel Sander

It was simple and did exactly as advertised.

15 Mar 2004 Urs Schwarz (us)

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

Comment only
15 Mar 2004 Michael Robbins

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

Comment only

Contact us