MATLAB Function Data Types


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


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



8-bit signed integer


8-bit unsigned integer


16-bit signed integer


16-bit unsigned integer


32-bit signed integer


32-bit unsigned integer


64-bit signed integer


64-bit unsigned integer


single precision numerical data


double precision numerical data


logical values of 1 or 0, it represent true and false respectively


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


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


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 =


d =


un =


rn =


c =


Our experts are dedicated to your success, and here at 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. 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 are dedicated and committed to your success, here at 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