preview
Reads the first rows of a data file using import options.
Category: Language Fundamentals > Data Types
Syntax
T = preview(filename, opts)
Returns a table with the first rows that readtable(filename, opts) would read.
Description
preview is a cheap way to check that the import options select the right variables and types before reading a large file in full. Only a few lines are read, so it stays fast even for files with millions of rows.
Input arguments
filename- Name of a text or spreadsheet file.
opts- Import options object, for example from
detectImportOptions.
Output arguments
T- Table with at most eight rows.
Example
fid = fopen('scores.csv', 'w');
fprintf(fid, 'id,score\n1,2.5\n2,3.5\n3,4.5\n');
fclose(fid);
opts = detectImportOptions('scores.csv');
preview('scores.csv', opts)
Output
ans = 3×2 table
id score
__ _____
1 2.5
2 3.5
3 4.5
Notes
In MatLivre the import options argument is required.