How to repeat a 4d vector for n times

2 ビュー (過去 30 日間)
Saugata Bose
Saugata Bose 2019 年 6 月 6 日
コメント済み: Stephen23 2019 年 6 月 6 日
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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by