Split data into different arrays of different sizes?

Hi I have a huge vector of data and I would like to divide it into different groups according to a particular index so lets say my data is a= (1 2 3 4 5 6 7 8....) and my index is i= (1,2,3,4..) which sum is equal to the size of a. How can I split "a" vector according to the index "i"?

回答(2 个)

If a is the vector and index is i.
iwant = a(i)

3 个评论

Thanks but that only shortened my vector I want to group them in columns of specified elements according to the index
How your indices are given?
Is a vector i = (1 2 3 4 5 6...) etc

请先登录,再进行评论。

accumarray(index(:),a(:),[],@(v){v})

1 个评论

I got this error message: Second input VAL must be a vector with one element for each row in SUBS, or a scalar.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息

提问:

2018-10-1

评论:

2018-10-1

Community Treasure Hunt

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

Start Hunting!

Translated by