Effacer les filtres
Effacer les filtres

How to repeat a 4d vector for n times

2 vues (au cours des 30 derniers jours)
Saugata Bose
Saugata Bose le 6 Juin 2019
Commenté : Stephen23 le 6 Juin 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,

Réponse acceptée

Stephen23
Stephen23 le 6 Juin 2019
Modifié(e) : Stephen23 le 6 Juin 2019
Z = repmat(W,1,1,1,10)
  2 commentaires
Saugata Bose
Saugata Bose le 6 Juin 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 le 6 Juin 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."

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by