banner



How To Make Matrix In Matlab

Matlab – Matrix

A Matrix is a two-dimensional array of elements. In MATLAB, the matrix is created by assigning the array elements that are delimited by spaces or commas and  using semicolons to mark the end of each row. Now let'southward have a glance at some examples to empathise it meliorate.

Syntax:

a = [elements; elements]

Example: Creating a Matrix

MATLAB

x = [one 2 3;iv 5 half dozen;7 8 9]

y = [ 'Geeks' ; 'Geeks' ]

Output:

 Example: Knowing the size of the Matrix

MATLAB

x = [i 2 3 4;4 5 6 vii;vii 8 ix 10];

xSize = size(x)

y=[ 'Geeks' ; 'Geeks' ];

ySize = size(y)

Output:

Accessing the elements of a matrix

 To reference an element in a matrix, we write matrix(k, due north). Hither thou ande n are row and column indexes.

Example 1:

MATLAB

x = [1 2 three four;four 5 6 7;7 8 9 10];

x(3,2)

y=[ 'Geeks' ; 'Geeks' ];

y(1,ii)

Output:

To access multiple elements in the matrix, we write

matrix(x:y;,xy)

Instance two:

MATLAB

10 = [one 2 3 4;4 5 6 7;7 eight 9 ten];

x(:,:)

x(1:2,:)

x(:,2: end )

x(1:2,2:three)

Output:

Calculation elements/dimensions to a matrix

To add elements/dimension to a matrix we can utilize one of the following methods:

cat(dimension,A,B,….)

or

x = [A;B]

In the to a higher place syntax, A & B are matrices that nosotros need to pass into the office cat() or concatenate by using foursquare brackets. Hither dimension parameter must be either 1 or 2 for table or timetable input.

Instance 1:

MATLAB

x = [1 ii 3 four;4 5 6 vii];

y = [7 viii 9 10;11 12 13 xiv];

a = [10;y]

b = [x;11 12 thirteen xiv]

x(:,five)=[xv 16]

Output:

Example 2:

MATLAB

x = [1 2 iii 4;4 5 6 seven];

a = x([1,2,2,i],:)

b = x(:,[1,iii,2])

Output:

Example iii:

MATLAB

10 = [1 2 three 4;4 five half dozen 7];

y = [1 two iii iv;4 five 6 7];

a = true cat(1,ten,y)

b = cat(2,x,y)

Output:

Example 4: Deleting a row/cavalcade of a matrix

MATLAB

x = [one ii 3 4;4 5 6 seven;vii 8 ix 10];

x(3,:) = []

ten(:,3) = []

Output:

Note:

  • Dissimilar nearly of the programming languages, MATLAB array indexes get-go from one.
  • To perform operations(almost all) on the matrices, dimensions must exist the same.
  • A semicolon must exist added at each end of the statement in order to avoid multiple outputs.
  • In MATLAB, a string is a character array.
  • In MATLAB, length() gives the length of an assortment, and size() gives the size of a matrix.

Source: https://www.geeksforgeeks.org/matlab-matrix/

Posted by: singletontror1952.blogspot.com

0 Response to "How To Make Matrix In Matlab"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel