MATLAB: How to create a table with no specific number of rows and input various data types row by row

arraytable

Best Answer

I'm only guessing at what you mean by "no specific number of rows". "objresult.CountRows" looks like it know how many there are, but I actually don't know how those things work. Your while loop suggests that you need to check for more rows each time you read one.

In R2018a, you can do something like this:

t = table('Size',[0 2],'VariableTypes',{'string' 'double'},'VariableNames',{'F_State' 'ResultID'});
while row < objresult.CountRows
    t.F_State(row) = objresult.Item('F_State'); 
    t.ResultID(row) = double(objresult.Item('Result_ID'))
    ...
end

Prior to R2018a, only thing that needs to change is the call to table, just preallocate double and string column vectors. But the performance of that is not going to be great, because it's going to be growing the table at each iteration. Best if you know how many in advance, or if you grow it in chunks rather than one row at a time.