Reading a CSV file into a 2D cell array of strings
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Stephen23
le 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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!