Reading a CSV file into a 2D cell array of strings
古いコメントを表示
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.
John Feiereisen
2022 年 5 月 6 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!