matrix repetition

23 ビュー (過去 30 日間)
zozo
zozo 2012 年 1 月 9 日
Hello,
I have a matrix M of dimensions (m by n). I want to repeat this matrix 'k' number of times along the column.
For example:
If
M=[1 3 4 5;4 5 6 7;9 3 4 2]
and k=4(say),then
out=[1 3 4 5 1 3 4 5 1 3 4 5 1 3 4 5;4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7;9 3 4 2 9 3 4 2 9 3 4 2 9 3 4 2]
please help.
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 1 月 9 日
reshape(M(:,:,ones(k,1)),size(M,1),[])

サインインしてコメントする。

採用された回答

Rick Rosson
Rick Rosson 2012 年 1 月 9 日
out = repmat(M,1,k);
  1 件のコメント
zozo
zozo 2012 年 1 月 9 日
Thank you sir! :)

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 1 月 9 日
repmat(M, 1, 4)
(Note: your example only uses 3 repetitions for the first row)
  1 件のコメント
zozo
zozo 2012 年 1 月 9 日
sorry..it shud be 4. dats my mistake.
thanks! :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by