Search code examples
matlabassigncell-array

MATLAB - Cell array to a cell


I want to create a {1,2} cell array, that will contain single cell value in {1,1} and several cells in {1,2}{:,1} row:

TEXT = {'-1';'432';'a';'c';'v';'-1';'-1';'14';'b';'n';'-1';'-1';'44';'m';'t';'r';'-1';'-1';'55';'o';'i';'u';'-1'};

Sections{1,1} = TEXT{5}; 
Sections{1,2}{:,1} = TEXT{3:10,1}; 

,but I get an ERROR:

The left hand side is initialized and has an empty range of indices.
However, the right hand side returned one or more results.
Error in fff (line 4)
Sections{1,2}{:,1} = TEXT{3:10,1}; % Text in the section

Ideas?


Solution

  • Just use () instead of {} for the sections in (n,2):

    TEXT = {'-1';'432';'a';'c';'v';'-1';'-1';'14';'b';'n';'-1';'-1';'44';'m';'t';'r';'-1';'-1';'55';'o';'i';'u';'-1'};
    
    Sections{1,1} = TEXT{5}; 
    Sections{1,2} = TEXT(3:10,1);