How to repeat a 4d vector for n times

2 visualizaciones (últimos 30 días)
Saugata Bose
Saugata Bose el 6 de Jun. de 2019
Comentada: Stephen23 el 6 de Jun. de 2019
Hi,
I have a 4d vector, W of size (1 x 1 x 8 x 100). I want to reshape the vector of size (1 x 1 x 8 x 1000) where the value of W will be copied after every 100 dimension.
Input:
W =val(:,:,1,1) = -0.0018
val(:,:,2,1) = 0.0045
... ... ... ... ... ... ... ... ...
val(:,:,8,100) = 0.0034
Output:
Then after my desired computation W turns to be like this
val(:,:,1,1) = -0.0018
val(:,:,2,1) = 0.0045
... ... ... ... ... ... ... ... ...
val(:,:,8,100) = 0.0034
val(:,:,1,101) = -0.0018
val(:,:,2,101) = 0.0045
... ... ... ... ... ... ... ... ...
val(:,:,8,200) = 0.0034
val(:,:,1,201) = -0.0018
val(:,:,2,201) = 0.0045
... ... ... ... ... ... ... ... ...
val(:,:,8,300) = 0.0034
... ... ... ... .. ... ... ... ... ...
I am thinking to do this using procedural style but I think MATLAB haas much faster way to dot this computation which I do not know. Can you please advice me in this regard?
thanks,

Respuesta aceptada

Stephen23
Stephen23 el 6 de Jun. de 2019
Editada: Stephen23 el 6 de Jun. de 2019
Z = repmat(W,1,1,1,10)
  2 comentarios
Saugata Bose
Saugata Bose el 6 de Jun. de 2019
@Stephen: thanks. its so simple implementation wherever I am writing a few lines of procedural code for this. Does this simple code mean that repmat copy W 10 times? in that case, what does other 1 mean here?
Stephen23
Stephen23 el 6 de Jun. de 2019
"Does this simple code mean that repmat copy W 10 times? in that case, what does other 1 mean here?"
According to the repmat documentation: "B = repmat(A,r1,...,rN) specifies a list of scalars, r1,..,rN, that describes how copies of A are arranged in each dimension. When A has N dimensions, the size of B is size(A).*[r1...rN]. For example, repmat([1 2; 3 4],2,3) returns a 4-by-6 matrix."

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by