Automate splitting arrays to input into table

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)

Stephen23
Stephen23 on 12 Feb 2017
Edited: Stephen23 on 12 Feb 2017
The trick is to use mat2cell and cell2table, e.g.:
>> 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)
Use array2table, but use reshape(means,14,4) first.

Categories

Asked:

AG
on 12 Feb 2017

Answered:

on 13 Feb 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!