Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Nearly there with reading a delimited text file, but need some assistance...

Subject: Nearly there with reading a delimited text file, but need some assistance...

From: Ian Cowley

Date: 22 Oct, 2002 12:43:09

Message: 1 of 1

I've got a CSV file in which all the fields are also double-quoted. I need
to read said file into Matlab. However, another complication is that
several of the fields are optionally empty, and each line of the file
doesn't have the same number of entries. So a typical format might be:

"Hello","5","","seven","bridge","3.4","","","","","flibble"
"Hello","5","","seven","bridge","3.4","","","","",""
"5.6","0.45","",""
"","","","","4.5"

I wish to read in the empty fields, and have them either as blanks or
zeroes.
Using
M=textread('c:\test.txt', '%q','delimiter','\n', 'whitespace',',')
I can import the file as a nx1 cell array, where n is the total number of
fields in the CSV.
I wish to have (taking the above as a file example) a 4x11 cell array, with
(in this case) the last 7 and 8 cells for lines 3 and 4 being filled with
blanks.

Unfortunately, we're reading in a CSV generated by some third party
software, so can't change the file format.

Is this possible? Where am I going wrong?

--
Ian Cowley
ian at iancowley dot co dot uk
Cambridge, UK

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us