View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Consecutive vector spliter

4.9 | 16 ratings Rate this file 39 Downloads (last 30 days) File Size: 3.83 KB File ID: #24255 Version: 1.6

Consecutive vector spliter


Bruno Luong (view profile)


25 May 2009 (Updated )

Partition an input vector into smaller series of subvectors of consecutive elements

| Watch this File

File Information

It says all in the summary. Nothing fancy just a convenient tool for spitting vectors.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
29 Aug 2016 Clair

Clair (view profile)

15 Oct 2015 Omer Moussaffi

01 Mar 2015 Shabnam

01 Mar 2015 Shabnam

01 Feb 2015 Matt J

Matt J (view profile)

Finally got around to trying this. I like it a lot, but I don't understand how the COL input argument works. Clearer documentation on that with examples would help.

14 Jan 2015 Greg

Greg (view profile)

Excellent. Thank you.

29 Aug 2014 Xinyi Shen

This is a great function that I am looking for.
However, it would be more perfect if
1. the array can be unsorted.
2. the indices can be returned
For example, [s,i] = SplitVec([1 2 1 3 2 1])
s={[1 1 1],[2,2],[3]}
i={[1 3 6],[2,5],[4]}
I do not know if it is possible

10 Jun 2014 Bruno Luong

Bruno Luong (view profile)


SplitVec(a, @(v) [0; diff(v(1:end-1)).*diff(v(2:end))<0])

Comment only
09 Jun 2014 Michal Kvasnicka

OK ... I add the 'decrease' and 'increase' functions by:
case {'increase'}
fun = @(v) diff(v(:,1))<0;
case {'decrease'}
fun = @(v) diff(v(:,1))>0;

But, how to add functions for 'positive' and 'negative' values vector spliting?

Comment only
09 Jun 2014 Michal Kvasnicka

Will be possible to generalize this function to split vector on monotonical parts using ismonotinic function (

04 Dec 2012 K

K (view profile)

23 Sep 2012 Amro

Amro (view profile)

12 Jul 2012 Ueli Rutishauser

29 May 2012 Aditya

Aditya (view profile)

04 Feb 2011 Sauro Salomoni

Ingenious! Clearly explained and easy to follow. Thank you very much!

23 Feb 2010 John D'Errico

John D'Errico (view profile)

As you would expect of all of Bruno's submissions, it does exactly what it says it will do. Superb documentation.

23 Feb 2010 Tom Toner

Thanks a lot for such a great function!

04 Dec 2009 Joshua Arnott

Just what I was looking for!

28 May 2009 1.1

multiple column grouping capability

21 Jun 2009 1.2

correct bug when function handle is passed in second input

22 Jun 2009 1.3

Correct minor bug

07 Jul 2009 1.4

correct bug for empty array, group function
Add output types: 'firstval' 'lastval'

02 Feb 2010 1.5

fix the bug when 'loc' is required and when working down the columns of matrix

26 Aug 2011 1.6

New builtin outputs: blockID and subsetorder

Contact us