How to extract elements from an array in three different array
조회 수: 37 (최근 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에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!