Julia 101

Matrix
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15]
  1. When a colon is used in a matrix reference in place of a specific index number, the colon represents the entire row or column. For example, the statement A[1,:](read as “all columns in row 1”) returns the first row i.e 1 2 3 4 5. Similarly A[:,3] (read as “all rows in column 3”) returns the third column.
  2. The colon operator can also be used to extract multiple rows or columns. For example, the statement A[1:2,:] (read as “all columns from row 1 to row 2”) returns 1 2 3 4 5; 6 7 8 9 10and the statement A[:,1:2] (read as “all rows from column 1 to column 2”) returns 1 2; 6 7; 11 12
  3. To access the last element, last row or last column of a matrix, the keyword “end” can be used. The statements A[end]/A[end,end], A[end,:] and A[:,end] returns 15 , the last row and the last column of matrix A, respectively.
  4. Finally, using a single colon with a matrix name, like A[:] transforms the matrix into a single column. The statement A[1:end] does the same.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
MUHAMMAD SALMAN KABIR

MUHAMMAD SALMAN KABIR

Electrical Engineer | Signal Processing & Machine Learning Enthusiast