Automate splitting arrays to input into table
Show older comments
I have an array that contains a total of 56 numbers. I need to take the first 14 numbers, the next 14 numbers, etc. and create a table with 14 columns and 4 rows. The below code works, but I would like to automate the process with a for loop or another method so I can repeat the same process on arrays that are much longer. Any suggestions?
array2table([means(1:14);means(15:28);means(29:42);means(43:56)])
Answers (2)
>> M = randi(9,1,56);
>> X = mat2cell(M,1,[14,14,14,14]);
>> X = cellfun(@(c)c(:),X,'uni',0); % this might not be required
>> T = cell2table(X)
Peter Perkins
on 13 Feb 2017
0 votes
Use array2table, but use reshape(means,14,4) first.
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!