Copying a matrix into another larger matrix multiple times

6 ビュー (過去 30 日間)
Olu adroit
Olu adroit 2016 年 1 月 12 日
編集済み: Stephen23 2016 年 1 月 12 日
Hi all, I am trying to write a script that creates a larger matrix B from a smaller matrix A = [1;1;1;2;2;2;3;3;3;4;4;4] whereby A is copied into B in N times. E.g if N = 4, B = [1;1;1;2;2;2;3;3;3;4;4;4;1;1;1;2;2;2;3;3;3;4;4;4;1;1;1;2;2;2;3;3;3;4;4;4;1;1;1;2;2;2;3;3;3;4;4;4]. Thank you for your help in advance.
Adroit

採用された回答

Stephen23
Stephen23 2016 年 1 月 12 日
編集済み: Stephen23 2016 年 1 月 12 日
You don't need to reinvent the wheel using slow and inefficient nested loops, just use repmat:
>> A = [1,2,3,4];
>> B = repmat(A(:),4,1)
B =
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
>> BB = repmat({A},4,4);
If a cell contains an array with more than one element, then it shows a summary of that array:
>> X = {5}
X =
[5]
>> X = {5:6}
X =
[1x2 double]
but the data is still all there!:
>> X{1}
ans = 5 6

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by