Read contents of file as text
Read a file and search it for text of interest.
First, read the file
fileread.m into a character vector.
filetext = fileread('fileread.m');
Then, define the text to search for.
expr = '[^\n]*fileread[^\n]*';
Find and return all lines that contain the text
matches = regexp(filetext,expr,'match');
Display the first matching line.
filename— Name of file to read
Name of the file to read, specified as a character vector or string scalar.
fileread leverages automatic character set detection to determine
the file encoding.
Usage notes and limitations:
If the function
fileread reads the entire file, then all the
data must fit in the largest array that is available for code generation.