Read a CSV file that contains both text and numeric columns, without having to manually specify the column type using %f, %s, etc.
MATLAB functions such as "textscan" that can read files with columns of both text and numeric values require the user to specify the data type of each column, which can be tedious for anything but the simplest file. Instead, this function determines each column's data type automatically.
Creates a MATLAB structure from the data, with fieldnames matching the headers in the file.
See also: "ezwrite"
Paul Taylor (2020). EZread (https://www.mathworks.com/matlabcentral/fileexchange/11026-ezread), MATLAB Central File Exchange. Retrieved .
In 2012 Matlab released the function: readtable() which does nearly the same thing as ezread()
Nice job - worked on the first try and did exactly what I wanted it to do.
Works great, read quickly than csvread!!!!!
Works great on my mac for importing .csv files with mixed numeric and text columns from Excel! Glad I stumbled across this gem.
I have a csv file, but it is only reading in the headers and the next row. nothing else is being read in?
Very nice! This is just what I needed.
doesn't work even on the simplest of .cvs files
??? Error using ==> textscan
First input must be of type double.
Error in ==> ezread at 41
header_cell = textscan(header_str,'%q','delimiter',file_delim);
Error in ==> stringParsing at 5
out_struct = ezread('TEST.csv',',')
Exactly what I was looking for.
This is right what I needed to read in a CSV file! Nice tool!!!
Does not take into consideration whether a text field (within quotations) has a comma in it (i.e. ...,"new york, ny",...
Could someone please post the 'fixed' version?
Paul contacted me shortly after my comment and has now updated the code. I'll rate it 5.
Extremely useful, but the current version doesn't close the file after opening it. This snippet crashes on my machine at about i=500
Adding fclose(fid) to the end of the file solves the problem.
Amazing! I was going to suggest that Mathworks hire the author, but it looks like they already did.
Changed %s to %q to handle strings within double quotes that have a comma within them
Included reference to related "ezwrite" function in description
Updated description to better describe the functionality of the file