Question
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.
Expert Answer
John Michell
PhD Expert
Answered Aug 20, 2026
Sounds like data should be a cell array to which you insert 10x5 matrices.
replace:
data = cell(4,1);
And
T.data{i} = data;
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related matrix Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →