I would like to nest an n x m matrix into a table, by using a for loop to populate each row of the table with a corresponding matrix. I am running matlab 2018a. Below you can find example code: % create the table subject = [1; 2; 3; 4]; condition = {'cond1';'cond2';'cond3';'cond4'}; data = NaN(4,1); T = table(subject,condition,data); % populate the table with matrixes, using a for loop for i = 1:1:size(T,1) data = rand(10,5); T.data(i) = data; % ERROR Unable to perform assignment because the left and right sides have a different number of elements. end I thought it was possible to create nested tables. However, I am not sure, on account of the error. I know tables within tables exists, but I am unsure whether you can nest a matrix/array in a table. Therefore, it is also allowed to transform the data matrix to a table, and then nest the table in the table. Of importance, I want to retain the for loop mechanism to populate the table.
John Michell answered .
2025-11-20
data = cell(4,1);
And
T.data{i} = data;