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...

1 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2011-10-15
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 个评论
Thom
Thom 2011-10-15
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(:);?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by