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 (최근 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
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!