Reading a CSV file into a 2D cell array of strings
Ältere Kommentare anzeigen
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 Kommentare
Stephen23
am 5 Mai 2022
Use READCELL. If required first open the file and read lines to find the end of the header, then close and READCELL.
John Feiereisen
am 6 Mai 2022
Antworten (0)
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!