This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Read contents of file as text


text = fileread(filename)


text = fileread(filename) returns a character vector that contains the contents of the file specified by filename. Specify filename as a character vector or string.


Read and search the file Contents.m in the MATLAB® iofun directory for the reference to fileread:

% find the correct directory and file
io_contents = ...

% read the file
filetext = fileread(io_contents);

% search for the line of code that includes 'fileread'
% each line is separated by a newline ('\n')

expr = '[^\n]*fileread[^\n]*';
fileread_info = regexp(filetext,expr,'match');
Was this topic helpful?