matlab - Indexing Cell arrays for more efficient performance -
i have following code display 9-by-3 cell array:
data = cell (9,3); col1 = [2, 3, 5, 7, 8, 11, 12, 15, 16]; col2 = {[1 1], [1 5], [3 9], [4 2], [4 6], [6 2], [7 6], [6 9], [9 9]}; col3 = {[2 3 4 5 8],[1 3 5 8],[1 2 5 7 8],[1 2 3 6 7],[3 4 7 8],[2 4 8 9],[2 4 5 9],[4 5 7 9],[2 6 7 8]}; k = length(data); = 1:k data{i,1} = col1(i); data{i,2} = col2{i}; data{i,3} = col3{i}; end data
please, can code more efficiently written using form of indexing? thanks.
your have written code assign 9 x 3 cell array, can written as:
data2 = [num2cell(col1') col2' col3'] data2 = [ 2] [1x2 double] [1x5 double] [ 3] [1x2 double] [1x4 double] [ 5] [1x2 double] [1x5 double] [ 7] [1x2 double] [1x5 double] [ 8] [1x2 double] [1x4 double] [11] [1x2 double] [1x4 double] [12] [1x2 double] [1x4 double] [15] [1x2 double] [1x4 double] [16] [1x2 double] [1x4 double]
Comments
Post a Comment