Read contents of file as text
text = fileread(filename)
Read a file and search it for text of interest.
First, read the file
Contents.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.