I am using Matlab 2019 and I saved a large number of different tables with the same name, each in a .mat-file with a different name. I'd like to load them and save them in a new table together.
I need a table that has the same variables (variable1, variable2, variable3), and numbers but an additional dimension for the different .mat-files. I.e. in the dummy code below the size of the table allData should be: 2 x 3 x 2.
If I simply concatenate them like this [Results1.Inpts; Results2.Inpts], then the table is 4 x 3 and I cannot distinguish the data from the different files.
Also I have a large number of .mat-files, so I would like to automate it like done here (https://www.mathworks.com/matlabcentral/answers/233745-loading-mat-files-with-same-variable-name), which I tried to do for my table below, but it didn't work.
Please find my dummy code below.
%% Create data and .mat files
clc;
clear;
close all;
format long;
Names = {'variable1','variable2','variable3'};
Numbers1 = [2, 3, 4; 3, 4, 5];
Numbers2 = [1, 4, 10; 2, 6, 3];
Inpts = array2table(Numbers1,'VariableNames',Names);
save('Results1.mat');
clear Inpts;
Inpts = array2table(Numbers2,'VariableNames',Names);
save('Results2.mat');
clear;
%% Analyse data
files = dir('*.mat');
allData = table(size(files));
for ii=1:length(files)
aFileData = load(files(ii).name);
allData{ii} = aFileData.Inpts;
end