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.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 4월 25일

0 개 추천

A = 1:10;
n = 3;
C = kron(A,ones(1,n));

추가 답변 (2개)

Jan
Jan 2012년 4월 25일

0 개 추천

A = 1:10;
n = 3;
B = reshape(repmat(A, n, 1), 1, []);
Muhammad Affandi
Muhammad Affandi 2012년 4월 25일

0 개 추천

Thanks to both ans. But still it return ??? Out of memory. Type HELP MEMORY for your options.
Basically my work is like this:
A=1:16885575; n=16;
Both 'kron' and 'reshape' give out of memory statement. So any other alternative or suggestion?

댓글 수: 1

Oleg Komarov
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!

Translated by