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!