# Colon Notation Function using Matrices

2 visualizzazioni (ultimi 30 giorni)
ssmith il 16 Nov 2021
Risposto: Awais Saeed il 16 Nov 2021
I have two matrices
A = [-1, 2, -3; 4, -5, 6]
B = [0, -1; 2, 10; -4, 3]
And I need help understanding what is happening in these functions:
A(2,2:3)
B(:2)
ans =
-5 6
ans =
-1
10
3
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

the cyclist il 16 Nov 2021
Modificato: the cyclist il 16 Nov 2021
A(2,2:3)
means "the 2nd row, 2nd-through-3rd column of A".
B(:,2)
means "all rows, 2nd column of B".
I strongly recommend the MATLAB Onramp tutorial. It covers basic MATLAB like this.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Awais Saeed il 16 Nov 2021
understand the syntax first. To access an element from a matrix, you need to provide the row and column in which it resides.
% for example
A = magic(4)
A(3,2) % access element at row = 3, column = 2
: operator means to select a range of rows or coloums
A(:, 2) % access column = 2 from all rows. Use : to select all rows at once
A(1, :) % access entire row = 1. Use : to select all columns at once
A(1:3, 2:3) % access row from 1 to 3 and column from 2 to 3
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by