Need help understanding arrays

조회 수: 1 (최근 30일)
Joe
Joe 2013년 3월 12일
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.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 3월 12일
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

추가 답변 (1개)

Cedric
Cedric 2013년 3월 12일
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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by