Compiling and calling of MATLAB Functions

Source: Internet
Author: User

Write a function in MATLAB and call the Function Method in the main program.

 

It is the same as other programming languages,Sub-functions and primary functions must be stored in different files.,The file name is the function name..Files must be saved in current directory before calling.

Basic Function Structure:

Function [return Variable list] = function name (input variable List)

% Annotation statement

Detection of input and return variable formats

Function body

 

% -------- Example -----

Main function main. m
Y = test (X)
Sub-function test. m (the file name is the function name)
Function Z = test (X)
Z = x. * X;

% ------- Multi-dimensional output --------

[A, B, c] = AA (m, n)

 

In addition, there are recursive calls, that is, the function itself can be called within the function;

Variable input/output count processing.

Function A = convs (varargin)

A = 1;

For I = 1: length (varargin)

A = Conv (A, varargin [I]);

End

Compiling and calling of MATLAB Functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.