Reading files with headers into matlab
Wednesday, July 2nd, 2008Here's a handy code sniplet that enables you to read a file with columns of data with headers into MATLAB:
function importfile(filename) % import the file newdata = importdata(filename); % create new variables in the base workspace from these fields end
This will give you three variables in your workspace:
- colheaders: a list of all the variable names, extracted from the header
- data: a matrix with all your data in it
- textdata: essentially the same thing as colheaders