How to extract elements from an array in three different array
35 次查看(过去 30 天)
显示 更早的评论
suppose i have an array which stores 19 elements. How to extract first seven elements in one, then next five in another and remaining in third.
0 个评论
采纳的回答
Guillaume
2015-12-8
A = randi(100, 1, 19)
splits = [7 5];
B = mat2cell(A, 1, [splits, numel(A) - sum(splits)]);
celldisp(B)
Use cell arrays rather than numbered variables.
2 个评论
Guillaume
2015-12-10
I'm not sure what you want me to elaborate on. You just pass the length of the submatrices you want the main matrix to be divided into, to mat2cell.
更多回答(1 个)
另请参阅
类别
在 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!