필터 지우기
필터 지우기

Creating a matrix whose entries are matrix

조회 수: 1 (최근 30일)
Ali Baig
Ali Baig 2018년 5월 25일
편집: Ali Baig 2018년 5월 25일
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?

채택된 답변

Stephen23
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
Although perhaps what you want is toeplitz ?:
  댓글 수: 1
Ali Baig
Ali Baig 2018년 5월 25일
편집: Ali Baig 2018년 5월 25일
Thank you Stephen. I will look into the details of toeplitz.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ameer Hamza
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 CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by