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!