How to concatenate matrices

조회 수: 6 (최근 30일)
jake stan
jake stan 2018년 3월 2일
편집: Pawel Jastrzebski 2018년 3월 2일
Create a 4x4 magic matrix A. Use MATLAB to assemble a new matrix B. I'm not sure how to turn the 4x4 matrix A in to a 2x2 matrix B, where first row: A 2A, second row: A^2 A+2
A = magic(4)
B = [A 2A; A.^2 A+2]

채택된 답변

Pawel Jastrzebski
Pawel Jastrzebski 2018년 3월 2일
You must have got an error message when executing - what did it say? That should be your first clue as to what's wrong with the code.
In your case, the multiplication sign is missing '*'.
A = magic(4)
B = [A 2*A; A.^2 A+2]
Output:
>> B
B =
16 2 3 13 32 4 6 26
5 11 10 8 10 22 20 16
9 7 6 12 18 14 12 24
4 14 15 1 8 28 30 2
256 4 9 169 18 4 5 15
25 121 100 64 7 13 12 10
81 49 36 144 11 9 8 14
16 196 225 1 6 16 17 3
  댓글 수: 3
Pawel Jastrzebski
Pawel Jastrzebski 2018년 3월 2일
편집: Pawel Jastrzebski 2018년 3월 2일
"." means it's an 'element-wise' operation. You need to have two matrices of the same size and the respective elements in them will be multiplied/divied/raised to the power.
If you ommit the "." it's considered as a normal matrix operation.
Jan
Jan 2018년 3월 2일
@jake stan: A.^2 squares the elements of the array A, while A^2 calculates A*A with the matrix multiplication.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by