Summary of MATLAB matrix function

Source: Internet
Author: User

The basic data unit of MATLAB is a matrix, and its instruction expression is very similar to the customary form commonly used in mathematics engineering, in addition to input array input matrix directly with [], can also use function to generate matrix.

Ones () creates a matrix of all elements that are 1, which can be made into dimensions, .... variables

Zeros () creates a matrix of all elements that are 0, but the type is still not double type

Initializes a logical type of matrix: A = True (5,5) or a = False (5,5)

Eye () creates a matrix with a diagonal element of 1 and another element of 0

Diag () creates a diagonal matrix based on a vector, that is, the element of the vector is the diagonal element

Magic () Create Rubik's Cube matrix

Rand () creates a random matrix, subject to uniform distribution

RANDN () create random matrices, subject to normal distribution

Randperm () creating random line vectors

Horcat C=[a,b], horizontal aggregation matrix, can also be used with Cat (1,A,B)

Vercat C=[a; B], vertical aggregation matrix, can also be used with Cat (2,A,B)

Repmat (m,v,h) aggregates The matrix M in the vertical direction and aggregates the H-times in the horizontal direction

Blkdiag (A, b) creates a block diagonal matrix with a, and a block


    • The subscript of the MATLAB array starts with "1", which is different from the C language.
    • MATLAB Specifies that the storage order of matrix elements in memory is stored in the order of the columns , that is, after the 1th column is saved, the 2nd column is saved, and so on. For example, there is a 3x4-order matrix B, which is stored in the computer in the order shown in table 2-13. The C language is the order of the rows to hold the elements of the array, that is, after the 1th row, then save the 2nd row, and so on. Therefore, the corresponding access Order B (3) is accessed to B (3,1) b (10) to B (1,4).
    • Unlike the C language, Matlab matrices and arrays do not have to be defined in advance to dynamically increase
>> m=1m = 1 >> m (=2 m = 1 2 )
>> m (2,1) =3m = 1 2 3 0
    • Matlab Matrix, array can dynamically change shape reshape
>> a=-4:4a = -4-3 -2-1 0 1 2 3 4 >> a= reshape (A , 3,3)A = -4-1 2-3 0 3-2 1 4
    • Comparison of the consequences of array transpose, upper and lower symmetric switching and rotation operations
A = -4-1 2-3 0 3-2 1 4>> A '//transpose matrix ans = 4-3-2-1 0 1 2 3 4>> A ' ==a. '//Another transpose, only plural when both transpose inconsistent ans =//so the logical matrix is full true 1 1 1 1 1 1 1 1 1 >> Flip UD (A)//Upside downAns =-2 1 4-3 0 3-4-1 2 >> Flip LR (A)//Flip aroundAns = 2-1-4 3 0-3 4 1-2>> rot90 (A)//counterclockwise rotation 90 degrees ans = 2 3 4-1 0 1-4-3-2
    • Expansion of matrix replication method
>> A=reshape (1:9,3,3) A =     1     4     7     2     5     8     3     6     9>> A (+) =1111a =        &NB Sp  1           4           7           0&NBS P          2           5           8   &NBSP ;       0           3           6           9           0           0       &NBSP ;   0           0        1111>> A (:, 6) =2222a =      & nbsp    1           4           7         &NBSP ; 0 &NBSp         0        2222           2     &NBS P     5           8           0         &NBS P 0        2222           3           6   &N Bsp       9           0           0       &NBS p;2222           0           0           0        1111           0        2222
    • D
    • D
    • S
    • S
    • S
    • Ssds
    • S
    • S
    • S
    • S
    • S
    • S
    • S
    • S


From for notes (Wiz)

Summary of MATLAB matrix function

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.