Help Center
Variable creation and indexed assignment
B = A
B(i,j,...) = A
B = A stores the value of A in the variable B.
A
B
The = character assigns a value to a variable, whereas the == character compares the elements in two arrays.
=
==
example
B(i,j,...) = A assigns the elements of A to the indexed elements of B specified by the indexing expression B(i,j,...).
B(i,j,...)
expand all
Use the = sign to assign a value to a variable.
A = 2
Because A has a single element, it is a scalar. Assign multiple values to a variable to create a vector or matrix.
B = [2 4 6 8]
B = 1×4 2 4 6 8
C = [1 0; 0 1]
C = 2×2 1 0 0 1
You also can assign the contents of one variable to another. For example, overwrite the scalar stored in A with the vector in B.
A = B
A = 1×4 2 4 6 8
Create a 3-by-3 matrix, and then index the first row to assign new elements.
A = [1 2 3; 4 5 6; 7 8 9]
A = 3×3 1 2 3 4 5 6 7 8 9
A(1,:) = [10 10 10]
A = 3×3 10 10 10 4 5 6 7 8 9
With indexed assignment, the number of elements indexed on the left side must equal the number of new elements on the right side.
Introduced before R2006a
== | ( )
( )
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
Europe
Asia Pacific
Contact your local office