Need help understanding arrays
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
0 个评论
更多回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!