Array fields of an array of cells

Let's say I have an array of cells:

my_cell_array = {'Jimmy', 'Timothy', 'Charles', ...} 

Is there a compact way to define a single struct that has my_cell_array elements as field names? Elements of the new structure may contain empty cells or empty arrays.

+7
source share
2 answers

cell2struct is probably what you need.

 my_cell_array = {'Jimmy', 'Timothy', 'Charles'} s = cell2struct(cell(size(my_cell_array)), my_cell_array, 2) s = Jimmy: [] Timothy: [] Charles: [] 
+7
source

Try using this statement:

 cell2struct(cell(size(my_cell_array)),my_cell_array,2) 

It returns:

 ans = Jimmy: [] Timothy: [] Charles: [] 
0
source

All Articles