How does mat2cell work?
33 次查看(过去 30 天)
显示 更早的评论
Hello,
I have:
- a Matrix called Matrix_A with a size of 18x46092.
I would like to:
- separate it so, that I get 15364 cells (this is the amount of points, 46092/3, for the x, y and z coordinates), each of these cells containing a 18x3 matrix (18 points each).
I have already done it with a line someone gave me. It is for the mean of Matrix_A. It works.
Matrix_A = transpose(mat2cell(mean(cell2mat(Matrix_A)), 1, 3*ones(size(Matrix_A,2),1)));
Can someone please explain how cell2mat works, so that I can use it myself? A solution (a line of code) solves the problem right now, but this is the second or third time I want to do this and can't. That's why I would prefere an easy to understand explanaition.
Thank you!
Edit: I cannot post the Matrix_A data as it is too big.
0 个评论
采纳的回答
Steven Lord
2021-1-15
Let's try this with a slightly smaller matrix, so you can see what's going on.
A = reshape(1:24, [3 8])
Let's slice this into 3-by-2 chunks. We don't actually need to slice it row-wise (since we want each chunk to have 3 rows just like A has three rows) but we do need to slice it column-wise.
rowSliceSizes = 3; % Each cell has three rows like A does
columnSliceSizes = [2 2 2 2]; % Each cell contains 2 columns of A
Now slice.
C = mat2cell(A, rowSliceSizes, columnSliceSizes)
celldisp(C)
Now let's slice A into a 2-by-3 cell array. Each cell in the first row of the result should contain 2 rows of A and each cell in the second row should contain the third row of A. Each cell in a column of the result contains 3, 2, and 3 columns of A respectively:
D = mat2cell(A, [2 1], [3 2 3])
celldisp(D)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!