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!