The error seems to suggest that you are assigning conflicting values to your table variable 't'. This might be happening because you are reusing the same variable name 't' to mean different tables during each iteration. Something like this would be the obvious thing to do in MATLAB but, since you are generating C code, things are slightly different there. One way to make this work would be to create a cell array of the sub tables and then concatenate them in one call after the loop.
function t = table_concat_test
temp = cell(1,10);
for i=1:10
features = struct();
features.a = 1;
features.b = 2;
features.c = 3;
features.d = 4;
extra_info = struct();
extra_info.name = {'name'};
extra_info.age = 19;
temp{i} = [struct2table(features) struct2table(extra_info)];
end
t = vertcat(temp{:});
end
>> codegen table_concat_test
Code generation successful.
>> table_concat_test_mex
ans =
10×6 table
a b c d name age
_ _ _ _ ________ ___
1 2 3 4 {'name'} 19
1 2 3 4 {'name'} 19
1 2 3 4 {'name'} 19
1 2 3 4 {'name'} 19
1 2 3 4 {'name'} 19
1 2 3 4 {'name'} 19
1 2 3 4 {'name'} 19
1 2 3 4 {'name'} 19
1 2 3 4 {'name'} 19
1 2 3 4 {'name'} 19
Note that I had to change extra_info.name to a cellstr instead of string, since MATLAB unfortunately does not support code generation for string arrays at this point.