Skip to Main Content Skip to Search
Product Documentation

fileread - Read contents of file into string

Syntax

text = fileread(filename)

Description

text = fileread(filename) returns the contents of the file filename as a MATLAB string.

Examples

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 = ...
  fullfile(matlabroot, 'toolbox', 'matlab', 'iofun', 'Contents.m');

% 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');

See Also

fgetl | fgets | fread | fscanf | importdata | textscan | type

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS