MATLAB: How to create a table with one column containing all of the values from a structure with multiple fields

columnMATLABstructtable

How do I create a table with one column containing all of the values from a structure with multiple fields?

Best Answer

The following script will create a table "t" from the structure "myStruct", with each value in the structure as a different row in the table.
myStruct = struct('aaa', 10, 'bbb', 20, 'ccc', 30, 'ddd', 40);
names = fieldnames(myStruct);
myList = {};
for i = 1 : length(names)
myList{end + 1} = myStruct.(names{i});
end
t = table;
t.myData = myList';