user1912925
user1912925

Reputation: 781

Create a 3d array consisting of vectors

Here is a very quick one which should be simple to answer if I can explain myself adequately.

I want to create a 144 x 96 x 10000 array called A such that

A(1,1,:) = 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010....10000 etc.
....
A(144,96,:) = 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010....10000 etc.

I assume I should use a combination of ones and repmat but I cant seem to figure this one out.

Thanks.

Upvotes: 0

Views: 40

Answers (2)

Adrien
Adrien

Reputation: 1475

Permute will kill you on large arrays,... you can also try:

array= 0.001:0.001:1000;
A = repmat(reshape(array,1,1,numel(array)),[144 96 1]);

Upvotes: 2

Ander Biguri
Ander Biguri

Reputation: 35525

you could do it the following way:

array=0.001:0.001:1000;
M=permute(repmat(array,144,1,96),[1 3 2])

It looks like repmat doesn't like [144,96,1] so we will create it in other size and then just change the order of the dimensions with permute

Upvotes: 1

Related Questions