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,
댓글 수: 0
채택된 답변
Stephen23
2019년 6월 6일
편집: Stephen23
2019년 6월 6일
Z = repmat(W,1,1,1,10)
댓글 수: 2
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 Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!