Distribution in Array
이전 댓글 표시
Hi..
Let say i have a array A=1:10; I want every element in array A to distribute into array C for n-times. C will be like this: (eg n=3)
C=[1 1 1 2 2 2 3 3 3 4 4 4 .... 10 10 10]
Is there any function to do that?
What i did was like this:
A=1:10;
n=1:3;
C=sparse(length(n),length(A));
for i=1:length(A) C(:,i)=A(i); end
C=reshape(C,1,length(A)*length(n));
And i'm not working with array's length of 10. Instead about 10000000 and every element to repeat itself 15 times. Really keen to avoid using 'for' loops but dont know how.
Im new to matlab. Thanks in advance for your help.
채택된 답변
추가 답변 (2개)
Jan
2012년 4월 25일
A = 1:10;
n = 3;
B = reshape(repmat(A, n, 1), 1, []);
Muhammad Affandi
2012년 4월 25일
0 개 추천
댓글 수: 1
Oleg Komarov
2012년 4월 25일
It should be repmat not reshape.
Also, consider that:
16885575 * 16 * (8 bytes) = 2.0129174 gigabytes
Do you have a contiguous block ot that size? Otherwise you'll keep getting that error.
The main question is, what do you need such an array for? Maybe you could use loops (why do you want to avoid them?).
카테고리
도움말 센터 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!