How to extract elements from an array in three different array
22 ビュー (過去 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 件)
the cyclist
2015 年 12 月 8 日
One way:
A = rand(1,19);
B1 = A(1:7);
B2 = A(8:12);
B3 = A(13: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!