How can I read the contents of a large data array which has 7 columns, but has only 6 data entries every couple of lines?

I want to read a large space-delimited file which contains numeric data in the form:
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5 6 7
etc..
and transform it into a matrix which has no gaps in the 6-value rows (ie. shuffle all the data back such that there are less overall rows but no gaps on any row)
How is this possible please?

Answers (1)

Unfortunately, space-delimited files aren't very amenable to such shenanigans; one way would be to read the file on a line-by-line basis and determine there whether there is a missing field or not and skip it if so.
Alternatively, you can read into a cell array and work on it -- Matlab can't handle "jagged arrays" as ordinary arrays so the cell or a structure or the like is the alternative.
Probably the best way would be to have the application that creates the file tag the missing values w/ an indicator value for missing -- 'NaN' or some other indentifiable value. Or add a specific delimiter that can be read to indicate the missing field.

Categories

Asked:

on 11 Nov 2013

Answered:

dpb
on 11 Nov 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!