divide array into subarrays

6 ビュー (過去 30 日間)
ak135AK
ak135AK 2016 年 3 月 20 日
編集済み: Azzi Abdelmalek 2016 年 3 月 20 日
I am working with array, let's say x = [1:10]; I would like to create n subarrays out of it in following way. For example, n = 3;
x_1 = [1:3]
x_2 = [4:6]
x_3 = [7:end].
Is there any function, which does this automatically?
thanks

回答 (1 件)

Star Strider
Star Strider 2016 年 3 月 20 日
The mat2cell function will do what you want:
x = [1:10];
Out = mat2cell(x, 1, [3 3 4]); % Split Vector
Out{1} % Look
Out{2} % Look
Out{3} % Look
ans =
1 2 3
ans =
4 5 6
ans =
7 8 9 10

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by