Search code examples
matlabstructcell

How to convert cell of tables into single table in matlab


After loading Excel tables, a variables E contains cells of tables.

DIR=C:\Documents\myFiles
cd(DIR)

for i=1:3
     a=rand(3,1)
     b=rand(3,1)
     T=table(a,b)
     FN=strcat('B',num2str(i))
     save(FN,'T')
end

D=dir('*.mat')
for j=1:3
     E{j}=load(D(j).name )
end

A=vertcat(E{:})

The last step of conversion is not working. How it can be modified?


Solution

  • This works:

    A=[];
    for j=1:3
         E=load(D(j).name);
         A=vertcat(A,E.T);
    end
    

    If you rather have the load and the concatenation separated, then just

    A=[];
    for ii=1:3
         A=vertcat(A,E{ii}.T);
    end