Putting certain blocks of numeric array data into its own cell each in a cell array. - tried num2cell and an index method to do this...

3 views (last 30 days)
I need to put certain blocks of numeric array data into its own cell each in a cell array.
I have a 1364 rows by 16 columns array. I want to place the first lot of 11 rows of data into the first cell (to result in 176 values in the first cell) , then the second lot of 11 rows into the second cell (the next 176 values here) , the third lot of 11 into the third cell and so on. for example: from : array = AAAAA; AAAAA; BBBBB; BBBBB; CCCCC; CCCCC; ...... I need: cell array(1) = AAAAA; AAAAA and so on....
Because it is a 1364 rows grid, there should then be (1364/11) = 124 cell collumns along only one row in the cell array.
I have used the num2cell command to try and do this, and an index method to do it too, but neither seem to get exactly what I need. How should these two methods be written to get what I need?
I'm new to matlab so apologies if this is a really basic question. thanks
  1 Comment
Jan
Jan on 15 Oct 2011
It is easier to answer, if you post your code. Then we could fix the error, but without your code, we have to write it from scratch.

Sign in to comment.

Accepted Answer

Jan
Jan on 15 Oct 2011
A = rand(1364, 16);
B = reshape(A, 11, 1364/11, 16);
B = permute(B, [1, 3, 2]);
C = num2cell(B, [1, 2]);
C = C(:);
But inside NUM2CELL you have a FOR loop also, so it might be more efficient to write it explicitely:
C = cell(124, 1); % Pre-allocate
B = reshape(A, 11, 1364/11, 16);
for iC = 1:numel(C)
C{iC} = reshape(B(:, iC, :), 11, 16);
end
  1 Comment
Thom
Thom on 15 Oct 2011
Thanks very much! That helped so much! I will also remember to write in my code next time, In this instance I just didnt bother since I didnt have much confidence in them. What is C = C(:);?

Sign in to comment.

More Answers (0)

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!