MATLAB Answers


Is there a way, when reading a file to insert text between a deliminator.

Asked by Kathleen
on 22 Aug 2014
Latest activity Answered by AJ von Alt
on 22 Aug 2014

My file has a header line that looks like this

[Column a, Column b, column c, colunm d;]

and then following rows with information like this


I've been using the strtok function to separate the values but since there is no character between the commas in the third column, it doesn't recognize it as anything and shifts all my information over one column. Is there a way to insert a value into that column.




No products are associated with this question.

1 Answer

Answer by AJ von Alt
on 22 Aug 2014

Use strsplit with "Collapse Delimiters" disabled.

inputstr = '[1,1,,1;1,1,,1;1,1,,1]';
C = strsplit( inputstr , ',' , 'CollapseDelimiters' , 0 );
C = 
      '[1'    '1'    ''    '1;1'    '1'    ''    '1;1'    '1'    ''    '1]'


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today