how to assign part of a matrix to other matrix in matlab

后端 未结 2 788
抹茶落季
抹茶落季 2021-01-29 12:41

I have a 30 x 30 matrix, called A, and I want to assign B as the leftmost 30 x 20 block of A how can I do that?

Is this the correct way to do i

2条回答
  •  无人及你
    2021-01-29 12:51

    A_new = A(:,1:20)

    takes all the rows from A with this part A(:,) and the first 20 columns with this part A(,1:20)

    A_newis now 30x20

    You can also iterate over elements in two loops, but the above answer is easiest

提交回复
热议问题