Align a vector such that all of its derivatives are positive or negative

2 views (last 30 days)
1. I have a unidimensional time series vector as such:
2. I want to decompose the series into two vectors, one of the points with positive slopes and the other of points with negative slopes.
I can do this by using the commands:
positiveDer = originalVector(diff(originalVector)>0) http://imageshack.us/f/18/positiveder.jpg/
negativeDer = originalVector(diff(originalVector)<0) http://imageshack.us/f/407/negativeder.jpg/
3. As you can see both new vectors are characterized by "runs" of the majority derivative occasionally broken by the minority derivative. I would like to align the runs in such a way that they feed into one another such that the series is composed entirely of one derivative valence, the positive or negative 'majority" derivative.
I think this could be done first by splitting the positiveDer into subvectors into positive "runs" whenever a negative derivative is encountered, producing runs of different lengths: run_t, run_tPlus1, run_tPlus2,...
To align the the runs, I could subtract the first point of a run from the end point of the previous run: ans = run_tPlus1(1) - run_t(end) and then add the difference: run_tPlus1 + ans
This would need to be looped to align all the runs, and then all the subvectors must be concatenated back into one vector.
Please, how could I do this?
Thank you, Alex

Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!