# MATLAB Function Data Types

Syntax

• function [y1,...,yN] = myfun(x1,...,xM)

Description

function [y1,...,yN] = myfun(x1,...,xM) declares a function named myfun that accepts inputs x1,...,xM, returns outputs y1,...,yN. The declaration statement must be the first executable line of the function.

Save the function code in a text file with a .m extension. The name of the file should match the name of the first function in the file. The valid function names begin with an alphabetic character can contain letters, the numbers, underscores.

You can declare multiple local functions within the same file, or nest functions. In case if any function in a file contains a nested function, the all functions in file must use the end keyword to indicate the end of the function. The end keyword is optional.

Defining function in a matlab file:

Write a Function

Open a file in a text editor. Within the file, we can declare the function and add program statements:

function f = fact(n)

f = prod(1:n);

Function fact can accepts a single input argument n, and returns the factorial of n in output argument f.

MATLAB does not require any type declaration or dimension statements. MATLAB encounters a new variable name, and then it creates the variable and allocates appropriate memory space.

If the variable already exists, MATLAB replaces the original content with new content and allocates new storage space, where necessary.

For example,

Total = 42

The above statement creates 1-by-1 matrix named 'Total' and stores the value 42 in it.

Data Types Available in MATLAB

MATLAB provides 15 fundamental data types. Each data type stores data that is in the form of a matrix or array. Size of this matrix or array is a minimum of 0-by-0 and this can grow up to a matrix or array of any size.

The following table displays the most commonly used data types in MATLAB:

 Data Type Description int8 8-bit signed integer uint8 8-bit unsigned integer int16 16-bit signed integer uint16 16-bit unsigned integer int32 32-bit signed integer uint32 32-bit unsigned integer int64 64-bit signed integer uint64 64-bit unsigned integer single single precision numerical data double double precision numerical data logical logical values of 1 or 0, it represent true and false respectively char character data (strings are stored as vector of characters) cell array array of indexed cells, every one capable of storing an array of a different dimension and data type structure C-like structures, each structure having named fields capable of storing an array of a different dimension and data type function handle pointer to a function user classes objects constructed from a user-defined class java classes objects constructed from a Java class

Example

Create script file with following code:

str = 'Hello World!'

n = 2345

d = double(n)

un = uint32(789.50)

rn = 5678.92347

c = int32(rn)

When the above code is compiled and executed, so it produces the following result:

str =

Hello World!

n =

2345

d =

2345

un =

790

rn =

5.6789e+03

c =

5679

Our experts are dedicated to your success, and here at Assignmenthelptutors.com we provide you with successful MATLAB function and its DATA types answers that will keep you on track to completing your MATLAB function and its DATA types projects and homework on time, accurately and using current knowledge up to date. We understand how complicated it can be to know who to turn to with newer programming questions, MATLAB function and its DATA typesassignments are newer and more complicated than many of your previous programming assignments. Assignmenthelptutors.com dedication is to assisting you in developing the best MATLAB function and its DATA types homework every time, meeting the high demands you have of online MATLAB function and its DATA types assistance. Experts at Assignmenthelptutors.com are dedicated and committed to your success, here at Assignmenthelptutors.com.

Assignmenthelptutors.com is dedicated to outstanding service with:

• They always available representatives live online support (chat and email) 24/7;
• discounts for repeat customers;
• secure payment methods and 100% confidentiality;
• MATLAB function and its DATA types helps for students all over the world.
• No Plagiarism
• Referencing styles, Harvard, APA, IEEE