Reading a CSV file into a 2D cell array of strings
5 次查看(过去 30 天)
显示 更早的评论
I'm looking for a computationally efficient way of reading a CSV file containing numbers and strings, with a variable number of header lines before the column titles, and varying columns. Once you get down to the column data, these fles are usually a couple hundred columns and several hundred thousand lines. I'd like to return everything as a two-dimensional cell array of strings (both the text and the numbers). I can read the entire file pretty quick into a 1D string delimited by commas and EOL characters, and I can use strsplit to split the 1D string on the EOLs into a 1D cell array where each index is another line. I can, in turn, loop and use strsplit to split each line on the commas and build up a two dimensional cell array of strings dimensioned {row,col}. But this last step is amazingly slow.
Is there any 2D equivalent to strsplit where I can specify two different delimiters to split a 1D char array where it will split on one delimiter for rows and the other delimiter on columns?
3 个评论
Stephen23
2022-5-5
Use READCELL. If required first open the file and read lines to find the end of the header, then close and READCELL.
回答(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!