How to replace middle value of matrix 4x4 with the other matrix 2x2?
1 次查看(过去 30 天)
显示 更早的评论
I have matrix A with size 4x4, and I want to replace the middle value of matrix A(size 2x2) with matrix B, the matrix B have size 2x2. Thanks.
0 个评论
回答(1 个)
Wayne King
2014-2-6
编辑:Wayne King
2014-2-6
A = randn(4,4);
B = randi([0 1],2,2);
A([6 7 10 11]) = B;
I determined those linear indices using:
sub2ind([4 4],[2 2 3 3],[2 3 2 3])
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!