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
  1 件のコメント
Jan
Jan 2011 年 10 月 15 日
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.

サインインしてコメントする。

採用された回答

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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by