n = 500; disp ("make big struct matrix with three fields"); tic; a = struct ("x", cell (n, n), "y", cell (n, n), "z", cell (n, n)); toc disp ("splitting it into scalar structs using num2cell"); tic; b = num2cell (a); toc disp ("concatenating first 10 columns horizontally"); tic; horzcat (b{:, 1:10}); toc disp ("concatenating first 10 columns vertically"); tic; vertcat (b{:, 1:10}); toc clear b disp ("for loop over elements using indices"); tic; for i = 1:n*n a(i); endfor toc disp ("loop directly over elements"); tic; for x = a(:).' endfor toc disp ("a smaller struct array with many fields"); f = strcat ("x", cellstr (num2str ([1:10*n].', "%05d")(randperm (n), :)).'); f(2,:) = {cell(1, n)}; tic; a = struct (f{:}); toc disp ("for loop over elements using indices"); tic; for i = 1:n a(i); endfor toc disp ("loop directly over elements"); tic; for x = a(:).' endfor toc disp ("stat all files in /usr/bin/*, gather as cell"); files = glob ("/usr/bin/*"); tic; cellfun (@stat, files, "uniformoutput", false); toc disp ("stat all files in /usr/bin/*, gather as struct array"); tic; cellfun (@stat, files); toc