Main Content

type

Display contents of file

Description

example

type filename displays the contents of the specified file in the MATLAB® Command Window.

Examples

collapse all

Display the contents of the file diceRoll. Since diceRoll does not exist, but diceRoll.m does exist, MATLAB displays the contents of diceRoll.m.

type diceRoll
function [d1,d2] = diceRoll
str = '@()randi([1 6],1)';
d1 = str2func(str);
d2 = eval(str);
end

function r = randi(~,~)
r = 1;
end

Input Arguments

collapse all

File name to display, specified as a character vector or a string. filename can be an absolute or relative path and can include a path and a file extension. type supports file names with these extensions.

File ExtensionDescription
.mlxMATLAB Live Script — An interactive document created using MATLAB Live Editor
.mlappMATLAB App File — An app created using MATLAB App Designer
.mMATLAB Code — A MATLAB script, function, or class

If you do not specify a file extension and a file without an extension does not exist, then type assumes that the extension is .mlx, .mlapp, or .m. For example, if a file myscript.m exists, then the command type myscript displays the contents of that file.

type leverages automatic character set detection to determine the file encoding for MATLAB code (.m) and other text files.

See Also

| |

Introduced in R2006a