MATLAB Language Getting started with MATLAB Language Helping yourself


Example

MATLAB comes with many built-in scripts and functions which range from simple multiplication to image recognition toolboxes. In order to get information about a function you want to use type: help functionname in the command line. Lets take the help function as an example.

Information on how to use it can be obtained by typing:

>> help help

in the command window. This will return information of the usage of function help. If the information you are looking for is still unclear you can try the documentation page of the function. Simply type:

>> doc help

in the command window. This will open the browsable documentation on the page for function help providing all the information you need to understand how the 'help' works.

This procedure works for all built-in functions and symbols.

When developing your own functions you can let them have their own help section by adding comments at the top of the function file or just after the function declaration.

Example for a simple function multiplyby2 saved in file multiplyby2.m

function [prod]=multiplyby2(num)
% function MULTIPLYBY2 accepts a numeric matrix NUM and returns output PROD 
% such that all numbers are multiplied by 2

    prod=num*2;
end

or

% function MULTIPLYBY2 accepts a numeric matrix NUM and returns output PROD 
% such that all numbers are multiplied by 2

function [prod]=multiplyby2(num)
    prod=num*2;
end

This is very useful when you pick up your code weeks/months/years after having written it.

The help and doc function provide a lot of information, learning how to use those features will help you progress rapidly and use MATLAB efficiently.