From: Sean on 12 May 2010 15:50 "Kuroro Lam" <v5lam(a)engmail.uwaterloo.ca> wrote in message <hseuk0$9c8$1(a)fred.mathworks.com>... > I want to create an array that looks like this: > > ids = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6 ... N, N, N, N] >>ids = kron(1:N,ones(1,4))
From: Matt J on 12 May 2010 16:30 "Kuroro Lam" <v5lam(a)engmail.uwaterloo.ca> wrote in message <hseuk0$9c8$1(a)fred.mathworks.com>... > I want to create an array that looks like this: > > ids = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6 ... N, N, N, N] ======= Seems like a bad idea as it generates a lot of redundant data. What do you need it for?
From: Loren Shure on 13 May 2010 07:00 In article <hseuk0$9c8$1(a)fred.mathworks.com>, v5lam(a)engmail.uwaterloo.ca says... > I want to create an array that looks like this: > > ids = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6 ... N, N, N, N] > > Right now I'm using a for loop between 1 and N and concatenating each set of numbers on to the array. > > ids = [] > for i=1:N > ids = [ids ones(1,6)*i] > end > > This works perfectly fine, I'm just wondering if there might be better way of doing it. > Do you really need this expanded array, or could you work with 1:N and do what you need with bsxfun? If so, it could be more memory-efficient. -- Loren http://blogs.mathworks.com/loren http://matlabwiki.mathworks.com/MATLAB_FAQ
First
|
Prev
|
Pages: 1 2 Prev: how to break a big column matrix into 2d matrix? Next: IFontDisp Object in Matlab? |