Creating a matrix whose entries are matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Given a matrix
A = [-4 1 0; 1 -4 1; 0 1 -4];
I want to create a matrix B such that
B = [A I 0; I B I; 0 I B];
where I is identity matrix whose size is equal to size of A. How can I do this?
댓글 수: 0
채택된 답변
Stephen23
2018년 5월 25일
편집: Stephen23
2018년 5월 25일
>> A = [-4 1 0; 1 -4 1; 0 1 -4];
>> I = eye(size(A));
>> Z = zeros(size(A));
>> B = [A I Z; I A I; Z I A]
B =
-4 1 0 1 0 0 0 0 0
1 -4 1 0 1 0 0 0 0
0 1 -4 0 0 1 0 0 0
1 0 0 -4 1 0 1 0 0
0 1 0 1 -4 1 0 1 0
0 0 1 0 1 -4 0 0 1
0 0 0 1 0 0 -4 1 0
0 0 0 0 1 0 1 -4 1
0 0 0 0 0 1 0 1 -4
추가 답변 (1개)
Ameer Hamza
2018년 5월 25일
I am assuming the in your question, you wrote B by mistake on the Left side of the 2nds statement and they are actually matrix A. If you want to create a big matrix B then follow @Stephen's answer. But If you want them to remain as separate matrices, then you will need a cell array
B = {A I Z; I A I; Z I A};
B =
3×3 cell array
{3×3 double} {3×3 double} {3×3 double}
{3×3 double} {3×3 double} {3×3 double}
{3×3 double} {3×3 double} {3×3 double}
Access each matrix using curly bracket notation. B{1, 2} will access matrix in the first row and second column.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!