Need help understanding arrays

1 Ansicht (letzte 30 Tage)
Joe
Joe am 12 Mär. 2013
Let's say I have an array A = [1 2 3; 4 5 6]
A =
1 2 3
4 5 6
A(1:2) would simply be
1
4
And A(2:3) would be
4
2
Basically the the 1st and 2nd elements and the 2nd and 3rd elements.
So why then is A(1:2, 2:3)
2 3
5 6
Instead of
1 2
4 5
This is probably a silly question, but I just can't seem to understand this.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 12 Mär. 2013
for your case:
A ([1:2,2:3])
for:
A(1:2,2:3);% 1:2 - numbers rows, befor the comma
% 2:3 - numbers columns, after the comma

Weitere Antworten (1)

Cedric
Cedric am 12 Mär. 2013
It is not a silly question. Your first approach for indexing is called 'linear indexing'; it addresses A as if it were a column vector made of all columns of A appended. Try
>> A(:)
and you will understand. The second approach is subscript indexing of a block of A made of rows 1 to 2 and columns 2 to 3.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by