what

Lists the MATLAB files in a folder, grouped by type.

Category: Programming > Files and Folders

Syntax

what

Displays the code files, MAT-files and class folders of the current folder.

what folder

Does the same for folder.

s = what(folder)

Returns a struct with one field per file type.

Description

what filters a folder down to the files that matter to the program: scripts and functions (.m), live scripts (.mlx), data (.mat) and so on, hiding everything else. With an output, the struct fields can be passed to other functions, for instance s.m to loop over the function files.

Input arguments

folder
Folder name; relative to the current folder or a folder on the path.

Output arguments

s
Struct with fields path, m, mlx, mat, mex, p, classes, packages and others; each is a cell array of names.

Example

Only the code files are listed

mkdir lib
writelines('function y = f(x), y = x; end', 'lib/f.m');
writelines('plain', 'lib/notes.txt');
s = what('lib');
s.m
Output
ans = 1×1 cell

    {'f.m'}

See also

dir ls which exist