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 ?
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.
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')
Comment only