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?
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
dpb
2013-11-11
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!