WJA
WJA

Reputation: 7004

Display code in Command Window like 'help' in Matlab

I am looking for a way to display the code of a function (unformatted) in the command window. In this way I want to easily check what the expected input arguments are, the help text and perhaps some part of the code.

When writing

help functionname

I only get the help text

Is there a way to get the complete code?

Upvotes: 2

Views: 44

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112689

Solution for stantard (non built-in) functions

What you want can be done as

type functionname

Example:

>> type mean

function y = mean(x,dim,flag,flag2)
%MEAN   Average or mean value.
%   S = MEAN(X) is the mean value of the elements in X if X is a vector. 
%   For matrices, S is a row vector containing the mean value of each 
%   column. 
···

Work-around for built-in functions

Built-in functions don't have Matlab code; they are directly part of the interpreter. For those functions the above method doesn't work. For example:

>> type find
'find' is a built-in function.

However, usually there is still a function file, which consists of comments only. You can open it with

open find

This will open the file find.m in the Matlab editor, which contains:

%FIND   Find indices of nonzero elements.
%   I = FIND(X) returns the linear indices corresponding to 
%   the nonzero entries of the array X.  X may be a logical expression. 
%   Use IND2SUB(SIZE(X),I) to calculate multiple subscripts from 
···

Upvotes: 4

Related Questions