Docsity

MATLAB Data Types: Understanding Different Data Types in MATLAB, Summaries of Mathematics

Toggle sidebar
bg1
10/31/21, 4:15 PM
MATLAB - Data Types
https://www.tutorialspoint.com/matlab/matlab_data_types.htm
1/8
MATLAB - Data Types
MATLAB - Data Types
MATLAB does not require any type declaration or dimension statements. Whenever MATLAB
MATLAB does not require any type declaration or dimension statements. Whenever MATLAB
encounters a new variable name, it creates the variable and allocates appropriate memory space.
encounters a new variable name, it creates the variable and allocates appropriate memory space.
If the variable already exists, then MATLAB replaces the original content with new content and
If the variable already exists, then MATLAB replaces the original content with new content and
allocates new storage space, where necessary.
allocates new storage space, where necessary.
For example,
For example,
Total = 42
Total = 42
The above statement creates a 1-by-1 matrix named 'Total' and stores the value 42 in it.
The above statement creates a 1-by-1 matrix named 'Total' and stores the value 42 in it.
Data Types Available in MATLAB
Data Types Available in MATLAB
MATLAB provides 15 fundamental data types. Every data type stores data that is in the form of a
MATLAB provides 15 fundamental data types. Every data type stores data that is in the form of a
matrix or array. The size of this matrix or array is a minimum of 0-by-0 and this can grow up to a
matrix or array. The 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.
matrix or array of any size.
The following table shows the most commonly used data types in MATLAB −
The following table shows the most commonly used data types in MATLAB −
pf3
pf4
pf5
pf8

Partial preview of the text

Download MATLAB Data Types: Understanding Different Data Types in MATLAB and more Summaries Mathematics in PDF only on Docsity!

MATLAB - Data Types MATLAB - Data Types

MATLAB does not require any type declaration or dimension statements. Whenever MATLABMATLAB does not require any type declaration or dimension statements. Whenever MATLAB encounters a new variable name, it creates the variable and allocates appropriate memory space.encounters a new variable name, it creates the variable and allocates appropriate memory space. If the variable already exists, then MATLAB replaces the original content with new content andIf the variable already exists, then MATLAB replaces the original content with new content and allocates new storage space, where necessary.allocates new storage space, where necessary. For example,For example, Total = 42Total = 42 The above statement creates a 1-by-1 matrix named 'Total' and stores the value 42 in it.The above statement creates a 1-by-1 matrix named 'Total' and stores the value 42 in it.

Data Types Available in MATLAB Data Types Available in MATLAB

MATLAB provides 15 fundamental data types. Every data type stores data that is in the form of aMATLAB provides 15 fundamental data types. Every data type stores data that is in the form of a matrix or array. The size of this matrix or array is a minimum of 0-by-0 and this can grow up to amatrix or array. The 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.matrix or array of any size. The following table shows the most commonly used data types in MATLAB −The following table shows the most commonly used data types in MATLAB −

Sr.No. Sr.No. Data Type & DescriptionData Type & Description 11 int8int 8-bit signed integer 8-bit signed integer 22 uint8uint 8-bit unsigned integer 8-bit unsigned integer 33 int16int 16-bit signed integer 16-bit signed integer 44 uint16uint 16-bit unsigned integer 16-bit unsigned integer 55 int32int 32-bit signed integer 32-bit signed integer 66 uint32uint 32-bit unsigned integer 32-bit unsigned integer 77 int64int 64-bit signed integer 64-bit signed integer 88 uint64uint 64-bit unsigned integer 64-bit unsigned integer 99 singlesingle single precision numerical data single precision numerical data 1010 doubledouble double precision numerical data double precision numerical data 1111 logicallogical

d =d = 23452345 un = 790un = 790 rn = 5678.9rn = 5678. c =c = 56795679

Data Type Conversion Data Type Conversion

MATLAB provides various functions for converting, a value from one data type to another. TheMATLAB provides various functions for converting, a value from one data type to another. The following table shows the data type conversion functions −following table shows the data type conversion functions −

FunctionFunction^ PurposePurpose char char (^) Convert to character array (string)Convert to character array (string) int2strint2str^ Convert integer data to stringConvert integer data to string mat2str mat2str Convert matrix to stringConvert matrix to string num2str num2str (^) Convert number to stringConvert number to string str2double str2double (^) Convert string to double-precision valueConvert string to double-precision value str2num str2num (^) Convert string to numberConvert string to number native2unicodenative2unicode Convert numeric bytes to Unicode charactersConvert numeric bytes to Unicode characters unicode2nativeunicode2native^ Convert Unicode characters to numeric bytesConvert Unicode characters to numeric bytes base2dec base2dec (^) Convert base N number string to decimal numberConvert base N number string to decimal number bin2dec bin2dec (^) Convert binary number string to decimal numberConvert binary number string to decimal number dec2base dec2base Convert decimal to base N number in stringConvert decimal to base N number in string dec2bin dec2bin (^) Convert decimal to binary number in stringConvert decimal to binary number in string dec2hex dec2hex (^) Convert decimal to hexadecimal number in stringConvert decimal to hexadecimal number in string hex2dec hex2dec (^) Convert hexadecimal number string to decimal numberConvert hexadecimal number string to decimal number hex2num hex2num Convert hexadecimal number string to double-precision numberConvert hexadecimal number string to double-precision number num2hex num2hex (^) Convert singles and doubles to IEEE hexadecimal stringsConvert singles and doubles to IEEE hexadecimal strings cell2matcell2mat^ Convert cell array to numeric arrayConvert cell array to numeric array cell2struct cell2struct (^) Convert cell array to structure arrayConvert cell array to structure array cellstr cellstr Create cell array of strings from character arrayCreate cell array of strings from character array mat2cell mat2cell (^) Convert array to cell array with potentially different sized cellsConvert array to cell array with potentially different sized cells num2cell num2cell (^) Convert array to cell array with consistently sized cellsConvert array to cell array with consistently sized cells struct2cell struct2cell (^) Convert structure to cell arrayConvert structure to cell array

Determination of Data Types Determination of Data Types

Create a script file with the following code −Create a script file with the following code − x x == 33 isinteger isinteger((xx)) isfloat isfloat((xx)) isvector isvector((xx)) isscalar isscalar((xx)) isnumeric isnumeric((xx)) x x == (^) 23.5423. isinteger isinteger((xx)) isfloat isfloat((xx)) isvector isvector((xx)) isscalar isscalar((xx)) isnumeric isnumeric((xx)) x x == [[ 11 22 33 ]] isinteger isinteger((xx)) isfloat isfloat((xx)) isvector isvector((xx)) isscalar isscalar((xx)) x x == (^) 'Hello''Hello' isinteger isinteger((xx)) isfloat isfloat((xx)) isvector isvector((xx)) isscalar isscalar((xx)) isnumeric isnumeric((xx)) When you run the file, it produces the following result −When you run the file, it produces the following result − x = 3x = 3 ans = 0ans = 0 ans = 1ans = 1 ans = 1ans = 1 ans = 1ans = 1 ans = 1ans = 1 x = 23.540x = 23. ans = 0ans = 0 ans = 1ans = 1 ans = 1ans = 1 ans = 1ans = 1 ans = 1ans = 1 x =x = Live Demo Live Demo

x = Hellox = Hello

  • 11 22
  • ans = 0ans =
  • ans = 1ans =
  • ans = 1ans =
  • ans = 0ans =
  • ans = 0ans =
  • ans = 0ans =
  • ans = 1ans =
  • ans = 0ans =
  • ans = 0ans =