MATLAB data type _matlab

Source: Internet
Author: User
Tags map class scalar sin
MATLAB data type

MATLAB data type numeric value type integer 8 integer type integral function floating point number 2 kinds of floating-point numbers double-precision float participation Operation complex complex numbers correlation function inf and Nan character and string structure create structure object using struct function to create structure access Structure object connection structure object cell array create cell array use assignment statement to create a cell array use the cell function to create an empty cell array a cell array of cells an array of operations cell arrays the cell array to use a merge delete cell an array of cells a specified unit in an arrays of cells using the reshape function to change a function handle function handle function mapping container create Map object view and read map object Edit Map Object Delete keysvalues add keysvalues to modify keys and values data type recognition and conversion data type recognition data type conversion

Numeric type integer 8 integer type type conversion function signed 8-bit int8 unsigned 8-bit uint8 int16 uint16 int32 uint32 Int64 uint64 integer function operation rule floor take the whole ceil up Rou nd take the closest integer, if the decimal part is divided into 0.5, then to the absolute value of the integer fix to 0 to take the whole floating point number 2 kinds of floating-point number type type bit width conversion function single precision double double double-precision floating-point participation operation

Return value types depend on other data types that participate in the operation other data types return type logical type, character double progress floating-point integer integer type single precision floating-point type single-precision floating point type

Note: A single-precision floating-point type cannot be counted directly with an integer type EPS function

Gets the gap complex number between a numeric value and the floating-point number closest to the value

The character I or J defaults to the imaginary part flag, can be entered directly in the plural form or by using the complex function complex correlation function function explanation complex (A,B) constructs with a as real part, B is imaginary part complex real (z) returns to the actual part imag (z) returns the imaginary part abs (z) returns the model ANGL E (z) returns the spoke angle Conj (z) returns the conjugate plural inf and nan

The INF represents a positive infinity,-inf represents a negative infinity, and Nan represents a non-numeric character with a string

A string is typically an array of values of ASCII values, displayed as a string expression that can be accessed by subscript on any of the elements

Stringname = ' Good boy '
Structure

A structure can store multiple different types of data in a field, which is equivalent to a data container that encapsulates different types of data that are associated with each other to create a structure object by assigning values to a field

Patient.name = ' John Doe ';
patient.billing = 127.00;
Patient.test = [75,45,45;45,67,79;545,451,541];
Creating structures using the struct function
Patient = struct (' name ', ' John Doe ', ' billing ', 127.00, ' test ', [75,45,45;45,67,79;545,451,541]);
Accessing Structure objects
Patient.name = ' John ';
Patient.age =;
P1 = patient, pname = Patient.name
Connecting Structure objects
patient1 = struct (' name ', ' John ', ' age ',);
 Patient2 = struct (' name ', ' Amy ', ' age ',);
 Patient = [Patient1,patient2]

Patient Properties:

Name          Size            Bytes  Class     Attributes

  patient       1x2               606  struct              
Array of cells

A cell array is a generalized matrix in which each cell can contain an array, an array of arrays, a string array, an array of structures, or another array of cells, so that each cell can have different dimensions and memory footprint. Creating cell arrays using Assignment statements to create cell arrays

"{}" Create, "," or space-delimited units, ";" Branch

A = {' x ', [2;3;6];10,pi}
To create an empty cell array using the cell function
B = cell (2,2)

Creating an empty cell array using the cell is primarily to allocate contiguous storage space for the array of cells, and to improve execution efficiency. Access cell arrays

In the cell array, the unit and the contents of the unit belong to different categories, the content of the Access Unit and unit is two different operations, MATLAB design two kinds of corresponding operation: the unit outside the identification and the unit address
The outside of the cell is marked with parentheses, and for the cell array c,c (M,N) is the cell in the row N columns of column m in the cell array
Within a cell, a brace operation is used for a cell array c,c (M,n) to refer to the contents of the cell in column m row n columns in the cell array.

A = {' x ', [2;3;6];10,pi};
b = A (1,2), C = a{1,2}

Results:

b = 

    [3x1 double]


c =

     2
     3
     6
Operation of a cell array

The operation of a cell array includes merging, deleting a specified cell in a cell array, and changing the array of cells in a cell array

A = {' x ', [2;3;6];10,pi};
B = {' Jam '};
C = {A B}

Results:

C = 

    {2x2 cell}    {1x1 cell}
Deletes a specified cell from a cell array

Simply assign the empty matrix to the unit, that is: c{m,n} = []

A = {' x ', [2;3;6];10,pi};
 a{1,2} = []

Results:

A = 

    ' x '           [] [    3.1416]
To change the shape of a cell array using the Reshape function
A = {' x ', [2;3;6];10,pi};
 Newa = Reshape (a,1,4)

Results:

Newa = 

    ' x '    [ten]    [3x1 double]    [3.1416]
function handle

function handles provide a method of indirectly calling a function to create a function handle

To create a generic syntactic format for a function handle:
Function_handle = @Function_Filename;
which
* Function_filename is the name of the M file corresponding to the function or the name of the MATLAB internal function
* @ is the handle creation operator
* The Function_handle variable holds this function handle and is passed as a data stream in subsequent operations

F_handle = @sin;
F_handle (0.25*PI)

Results:

Ans =

    0.7071
function handle functions function name function Function_handle or @ Indirect call function Func2str converts a function handle to a function name string Str2func Converts a function represented by a string to a function handle functions (Funhandle) Returns a structure that stores the name of the function, the type of function, and the location of the function m file
F_handle = @sin, F1 = Functions (f_handle), t = Func2str (f_handle), f_handle1 = Str2func (t)

Results:

F_handle = 

    @sin


f1 = 

    function: ' Sin '
        type: ' Simple '
        file: '


t =

sin


f_handle1 = 

    @sin
Mapping container

The mapping container (map containers, also called a Map object) is the mapping of one quantity to another. For example, if you map a string to a numeric value, the corresponding string is the mapped key (key), and the corresponding value is the mapped data (value). The map container can be understood to be a quick key lookup data structure
The index of searching for a map element is called a "key". A "key" can be any of the following data types:
* 1xN String
* Single or double-precision real scalar
* Signed or unsigned scalar integers
The key and its corresponding data are stored in the mapping container, and there are one by one corresponding relationships. The data type stored in the mapping container p can be any type, including numeric type, character or string type, struct type, cell type, or other mapping container.
A single mapping container object is an object of the Matlab map class. All objects of the map class have 3 attributes (listed in the following table) that the user cannot modify directly, but can be modified through the Map class action function. Property describes the default value Count unsigned 64-bit integer representing the total number of key/value pairs stored in the map object, 0 KeyType strings, representing the type char valuetype string of the key contained in the Map object, representing the data type contained in the map object any

Property's View Method: Map name + "." + Map Property name
For example, to view the data types that the Mapobj object contains, you can use:

Mapobj.valuetype
Create a Map object

The map construction method is as follows:
Mapobj = containers. Map ({key1, Key2, ...}, {val1, Val2, ...})
When the key and the value are strings, you need to make a slight change to the above syntax, namely:
Mapobj = containers. Map ({' keystr1 ', ' keystr2 ', ...}, {val1, Val2, ...})

K = {' Before ', ' Feb ', ' Mar ', ' Apr ', ' may ', ' June ', ' may ', ' Aug ', ' Sep ', ' Oct ', ' Nov ', ' Dec ', ' annual '};
 v = {327.2, 368.2, 197.6, 178.4, 100.0, 69.9, 32.3, 37.3, 19.0, 37.0, 73.2, 110.9, 1551.0};
 Rainfallmap = containers. Map (K,V)
Whos rainfallmap
  Name              Size            Bytes  Class             Attributes

  rainfallmap  13x1 112 Containers. Map

In addition, the creation of a map object can be divided into two steps: Create an empty Map object first, and then add content to it using the keys and values methods. The empty map object is created as follows:

Newmap = containers. Map ()
To view and read a map object

Each entry in a Map object consists of two parts: a unique key and its corresponding value. You can view all the keys contained in a map object by using the keys function, and view all values through the Vales function.

KV = keys (rainfallmap), VV = VALUES (RAINFALLMAP)

Results:

KV = 

  1 to 12 column

    ' annual ' '    Apr '    ' Aug ' '    Dec ' '    Feb '    ' may ' '    Nov '    Oct '

  13 column

    ' Sep '


vv = 

  1 to 9 columns

    [1551] [    178.4000]    [ 37.3000]    [110.9000] [    368.2000] [    327.2000]    [32.3000] [    69.9000]    [197.6000]

  10 to 13 [+

    ]    [73.2000] [    Panax]    [19]

The user can search the map object for data. The following format is used for the value of the specified key:
VALUENAME = Mapname (KeyName)

When a key name is a string, use single quotes to enclose the key name

V5 = Rainfallmap (' May ')

Results:

V5 =

   100

If you need to access multiple keys, you can use the values function

vs = VALUES (Rainfallmap, {' Before you ', ' Dec ', ' annual '})

Results:

vs = 

    [327.2000]    [110.9000]    [1551]

When accessing multiple keys, you cannot use the colon ":" As you would in other data types, which results in an error resulting in Edit Map object deletion keys/values

Remove Keys/values from the Map object using the Remove function
Remove (mapname, KeyName) add keys/values to

Add keys/values directly to the map object
Mapname (KeyName) = value modifies keys and values

If you want to make changes to the key name without changing the value, first delete the key name and the corresponding value, and then add a new entry with the correct key name

Remove (Rainfallmap, ' from the ");
Rainnfallmap (' The ' All-about ') = 327

The value in the Map object can be modified by an assignment operation
Rainfallmap (' Mar ') = 33.3 data type recognition and conversion data type recognition function Description function Indicates whether ISA belongs to a particular class isnumeric whether it is a numeric array Whether the Iscell is a cell array isobject whether it is a Matlab object iscellstr whether it is a character cell array isreal whether the literal Ischar is a character array isscalar whether it is a scalar isfield whether it is a field of the class Isstr Whether the string isfloat whether it is a floating-point number isstruct whether it is a structure array ishghandle whether the graphics object handle Isvector is a vector isinteger whether the class of the integer array class object is Isjava whether it is Java class V Alidateattributes Verify array validity islogical Whether it is a logical array whos enumeration variable type related data data type conversion function Description function Description char convert to character type Dec2bin decimal value to binary value INT2STR Integer conversion to string dec2hex Decimal numeric value converts to hexadecimal numeric mat2str matrix to string Hex2dec hexadecimal numeric value to decimal numeric num2str numeric conversion to string Hex2num hexadecimal numeric value to double value STR2DOUBL E-string conversion to floating-point number Num2hex Double-precision numeric value converted to hexadecimal numeric str2num string number convert to numeric Cell2mat cell array convert number array Native2unicode numeric byte to Unicode character cell2struct cell Array to structure array unicode2native Unicode to numeric byte cellstr create a cell array from a string Base2dec converts a numeric value of N to a decimal Mat2cell matrix array into a cell array bin2dec The binary numeric value is converted to the decimal Num2cell the numeric array converts the Dec2base decimal value into the cell array into the cell array, and the numeric Struct2cell structure array is converted to a unit

.

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.