Reputation: 790
I have a 1437X159X1251 large matrix and I want to insert a 1437x159 matrix into the middle of the larger matrix, making the large matrix 1437x159x1252 large. How would I do that? Thanks.
Upvotes: 0
Views: 721
Reputation: 38032
For horizontal or vertial concatenation of matrices/vectors A
and B
, you can use
% vertical
[A; B];
% horizontal
[A, B]; % comma is optional:
[A B];
There is no such notation for the third dimension. You'll have to use the generalized concatenation in arbitrary dimension cat()
:
% Example matrices
A = rand(1437, 159, 1251);
B = rand(1437, 159);
% Insertion point
N = 384;
% How to do it
A = cat(3, A(:,:,1:N), B, A(:,:,N+1:end));
Upvotes: 1