How to repeat a 4d vector for n times

2 次查看(过去 30 天)
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,

采纳的回答

Stephen23
Stephen23 2019-6-6
编辑:Stephen23 2019-6-6
Z = repmat(W,1,1,1,10)
  2 个评论
Saugata Bose
Saugata Bose 2019-6-6
@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 2019-6-6
"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."

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by