readcell
Reads a spreadsheet or delimited text file into a cell array.
Category: Data Import and Analysis > Data Import and Export
Syntax
C = readcell(filename)
Reads every cell, keeping numbers as numbers and text as text.
C = readcell(filename, opts)
Uses import options.
Description
Use readcell for data with mixed types in one block, where readmatrix would turn the text into NaN. Header rows are read as data, just like any other row. Empty cells are returned as a missing value.
Input arguments
filename- Text, CSV or spreadsheet file name.
opts- Optional import options object.
Output arguments
C- Cell array with one element per cell of the file.
Example
Mixed text and numbers
fid = fopen('m.csv', 'w'); fprintf(fid, 'name,age\nAnn,30\nBob,25\n'); fclose(fid);
C = readcell('m.csv')
class(C{2, 1}), class(C{2, 2})
Output
C = 3×2 cell
{'name'} {'age'}
{'Ann' } {[ 30]}
{'Bob' } {[ 25]}
ans = 'char'
ans = 'double'