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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by