SERVING THE QUANTITATIVE FINANCE COMMUNITY

JTB
Topic Author
Posts: 221
Joined: August 20th, 2010, 9:28 am

### MATLAB : Reading txt-file with delimiter problem

I have a file with the following structure:"Hans", "Hanson", "2","5.9000,14""Kim", "Jung", "3","5.9000,16"Trying dataset('File',folderIndex(i,1).name,'Delimiter',',') gives one extra column due to 5.9000,14-value is splitted into two extra columns. Any smooth fix for this problem?

Cuchulainn
Posts: 63251
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### MATLAB : Reading txt-file with delimiter problem

edit: (sorry, wrong post)
Last edited by Cuchulainn on September 6th, 2013, 10:00 pm, edited 1 time in total.
Chips chips chips Du du du du du Ci bum ci bum bum Du du du du du Ci bum ci bum bum Du du du du du
http://www.datasimfinancial.com
http://www.datasim.nl

tagoma
Posts: 18382
Joined: February 21st, 2010, 12:58 pm

### MATLAB : Reading txt-file with delimiter problem

(i've never used Matlab)i would try to cheat Matlab as follows:- open your file in notepad, CTRL+H replace $",$ with a $"+[blank space],$ - set your delimiter as blank space (probably something like $""$ with Matlab)

OOglesby
Posts: 42
Joined: August 26th, 2011, 5:34 am

### MATLAB : Reading txt-file with delimiter problem

JTB,Try the following code snipped and see if it can read your file. Textscan is a much more complicated function to use, but incredibly flexible. The text data will be stored in a cell array. There is plenty of documentation about cell arrays if you are not familiar with them.As a caveat, I have not tried this code to ensure no typos or bugs, but it should be a starting point.