Fill cell array with consecutive numbers in Matlab -


given mycellarray{10,3} = [];, fill in first column consecutive numbers (let's 1 through 10). know this:

[mycellarray{1:10,1}] = deal(1,2,3,4,5,6,7,8,9,10) mycellarray =      [ 1]    []    []     [ 2]    []    []     [ 3]    []    []     [ 4]    []    []     [ 5]    []    []     [ 6]    []    []     [ 7]    []    []     [ 8]    []    []     [ 9]    []    []     [10]    []    [] 

however, if cell array larger (say 1,000 rows rather 10), writing out comma-separated values becomes tedious:

[mycellarray{1:10,1}] = deal(1,2,3, ... ,1000)

is there way create comma-separated "list" of numbers automatically? (1:10)? know assign values via loops, there elegant one-line solution or close that?

this 1 way num2cell -

mycellarray(:,1) = num2cell(1:size(mycellarray,1)) 

in place of num2cell, can use mat2cell might not elegant though -

mat2cell([1:size(mycellarray,1)]',ones(1,size(mycellarray,1)),1) 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -