Documentation

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.

fileread

Read contents of file as text

Syntax

text = fileread(filename)

Description

example

text = fileread(filename) returns contents of the file filename as a character vector.

Examples

collapse all

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 'fileread'.

matches = regexp(filetext,expr,'match');

Display the first matching line.

disp(matches{1})
function out=fileread(filename)

Input Arguments

collapse all

Name of the file to read, specified as a character vector.

Example: 'myFile.dat'

Data Types: char

Introduced before R2006a

Was this topic helpful?