File Exchange

image thumbnail

SplitVec

version 1.9.0.0 (3.82 KB) by Bruno Luong
Partition an input vector into smaller series of subvectors of consecutive elements

3 Downloads

Updated 19 Jul 2018

View License

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

Cite As

Bruno Luong (2020). SplitVec (https://www.mathworks.com/matlabcentral/fileexchange/24255-splitvec), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (18)

Clair

Shabnam

Shabnam

Matt J

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.

Greg

Excellent. Thank you.

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])
where
s={[1 1 1],[2,2],[3]}
i={[1 3 6],[2,5],[4]}
I do not know if it is possible

Bruno Luong

Monotonic

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

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?

Will be possible to generalize this function to split vector on monotonical parts using ismonotinic function (http://www.mathworks.com/matlabcentral/fileexchange/11637-ismonotonic)?

K

Amro

Aditya

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

John D'Errico

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

Tom Toner

Thanks a lot for such a great function!

Updates

1.9.0.0

Output specific columns on split-array

1.8.0.0

Update tiltle and MATLAB version

1.8.0.0

extend 'type' with split column numbers

1.6.0.0

New builtin outputs: blockID and subsetorder

1.5.0.0

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

1.4.0.0

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

1.3.0.0

Correct minor bug

1.2.0.0

correct bug when function handle is passed in second input

1.1.0.0

multiple column grouping capability

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories