MATLAB: Simplify JSON Decode for Loop


Hi All,
I have some JSON data that I would like to flatten to a table. At the moment I am using a for loop to acheive this, but this is proving to be expensive in terms of time. Is there a way that I can do this without the loop.
% This is really inefficient, I need to optimise this.
varNames =';
varTypes = {'double','double','double','double','cell','double','double'};
t = table('Size',[ 7],'VariableTypes',varTypes,'VariableNames',varNames);
p = cell2table(;
for i =
t1 = p{i,1}{:,:}';
if isequaln(t1{:,6}, t1{:,7}) %if Lat & Long empty
t1{:,6} = nan;
t1{:,7} = nan;
t(i,:) = t1;

Best Answer

  • Hi,
    I found a solution, which has taken my code down from 45 to less than 0.5 seconds. See below for the record.
    p =;
    t = cell2table(horzcat(p{:})','VariableNames',');