I want to divide an array up into sections and add each section to its own column in a table.
Show older comments
I have an array that is 85x48 and I want to break it up into 6 sections of 85 x 8 and make each of those arrays into one column of a table.
ie. Columns 1-8 of the array will be column 1 of the table, columns 9-16 will be column 2 etc.
The size of my array (85x48) may change and thus the number of sections and their size might also change, so I need to set it up so there is not a set number of columns already in the table and I am just manually assigning the data each time.
I have tried using a for loop that determines the starting and ending column for each section and adds that to a table, but I do not know how to specify which column in the table I want it to be written to, so it only ever writes to the first column and writes over all of the previous data.
Any help would be greatly appreciated
rows = 8; %these numbers will change so the table needs to work for any iteration
columns = 6;
wells = 48;
example = rand(85,48);
n_end = 0:rows:wells; %creating an array to specify where the table should be cut
n_start = n_end +1;
n_end(1) =[];
n_start(end)=[];
n_times = [n_start;n_end];
for i = 1:columns
x = example(:,n_times(1,i):n_times(2,i));
Organized_table = table(x);
end
Accepted Answer
More Answers (1)
example = rand(85,48);
xcell=mat2tiles(example,[inf,8]);
Organized_table = table(xcell{:})
>> whos Organized_table
Name Size Bytes Class Attributes
Organized_table 85x6 34703 table
Categories
Find more on Logical 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!