What does the array mean?
조회 수: 1 (최근 30일)
이전 댓글 표시
A (end+1 : end+2, 1:2 ) = eye(2), what does this array mean?
댓글 수: 1
per isakson
2015년 9월 30일
Find out:
>> A = ones(4,4)
A =
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
>> A (end+1 : end+2, 1:2 ) = eye(2),
A =
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 0 0 0
0 1 0 0
답변 (2개)
John D'Errico
2015년 9월 30일
What does it mean? Nothing, besides the obvious. They are numbers. Actually, the array merely represents numbers.
Numbers, by themselves have no intrinsic meaning. It is to the person who creates such an array for which those numbers MAY have a meaning.
댓글 수: 0
Chad Greene
2015년 9월 30일
The eye function creates the identity matrix. It's just ones in a diagonal line, with zeros everywhere else. So
>> eye(2)
ans =
1 0
0 1
creates the 2x2 identity matrix you see above,
>> eye(3)
ans =
1 0 0
0 1 0
0 0 1
creates a 3x3 identity matrix, and so on.
The bit of code you wrote assumes you already have some matrix A. Perhaps A is a 3x2 matrix of all fives:
>> A = 5*ones(3,2)
A =
5 5
5 5
5 5
It doesn't matter what exactly is inside A. But this bit:
A(end+1:end+2
says we're gonna change the size of A. It says starting at the bottom row (the end) of A, ranging from rows end+1 to end+2, we're gonna tack on some new numbers. And to be specific, those new numbers will be placed in columns 1 to 2. So
A(end+1:end+2,1:2) =
says put something in two new rows added the bottom of A in columns 1 and 2. What will we put in these newly-added rows of A? How about an identity matrix?
>> A(end+1:end+2,1:2) = eye(2)
A =
5 5
5 5
5 5
1 0
0 1
The A matrix no longer has the dimensions 3x2. Now it's 5x2. But because we're using the end command instead of explicitly stating which row number to write or over-write, we can keep adding new rows to A. Perhaps you want to put some threes down there:
>> A(end+1:end+2,1:2) = 3*ones(2)
A =
5 5
5 5
5 5
1 0
0 1
3 3
3 3
Or some arbitrary numbers:
>> A(end+1:end+2,1:2) = [87 42; 6.3 9]
A =
5.0000 5.0000
5.0000 5.0000
5.0000 5.0000
1.0000 0
0 1.0000
3.0000 3.0000
3.0000 3.0000
87.0000 42.0000
6.3000 9.0000
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!