Hello Scott
As of MATLAB R2018b, "writetable" is not supported for nested tables. However, you can achieve something similar using the following workaround:
1. Create a file transformStruct.m with following contents
function [a b] = transformStruct(stArr)
a=[];
b={};
for i=1:length(stArr)
a(i) = stArr(i).a;
b{i} = stArr(i).b;
end
a=a';
b=b';
end
2. A file transformArr.m with following contents
function out = transformArr(arr)
out = {};
for i=1:size(arr,1)
out{i} = mat2str(arr(i,:));
end
out=out';
end
3. Finally a file main_script.m with contents
bob = struct();
bob.joe = [1; 2; 3];
bob.sam = ['4'; '5'; '6'];
bob.bill = [[6:10]; [11:15]; [16:20]];
bob.jim = [struct('a',1,'b','q'); struct('a',2,'b','r'); struct('a',3,'b','s')];
joe = bob.joe;
sam = bob.sam;
bill = transformArr(bob.bill);
[jim_a jim_b] = transformStruct(bob.jim);
T = table(joe, sam, bill, jim_a, jim_b);
writetable(T)
Place all three files in a directory, and run the file main_script.m
Best Answer