Wolpertinger
Wolpertinger

Reputation: 1301

MATLAB: repeat row vector in multiple dimensions

I want to create multidimensional arrays that repeat a vector along along the other dimensions. E.g. for row-vectors a and b I can create A which has A(:,n,m,k)=a for all n,m,k and similarly B which has B(n,:,m,k) for all n,m,k as follows:

A=repmat(a', [1 length(b) length(c) length(d)]); B=repmat(b, [length(a) 1 length(c) length(d)]);

How can I do the equivalent for C and D? I.e. such that C(n,m,:,k)=c where c is a row vector.

Upvotes: 1

Views: 149

Answers (1)

Wolpertinger
Wolpertinger

Reputation: 1301

Solved it myself, one can use the permute function, e.g.:

B=repmat(b, [length(x) 1 length(a) length(c)]); B=permute(B,[1 3 2 4]);

Upvotes: 1

Related Questions