Sunday, 28 April 2013

How to read a CSV file in octave and set empty cells to defaults


if foo.csv is a csv file with some empty values and a header row (also with some empty values) you can fill in defaults within octave using this method:

d = csv2cell('foo.csv')
e = cellfun('isempty', d)

eh = false(size(e))
en = false(size(e))

eh(1, :) = e(1, :)
en(2:end, :) = e(2:end, :)
d(eh) = {'No header name'}
d(en) = {NaN}