Deleting rows until a certain point

14 views (last 30 days)
Christian von Spreckelsen on 18 May 2016
I made a script that calculate some data and then plots it. I now want it to delete all the data up until a certain point. So to be more specific i want it to find the first 5 rows which values is greater that a certain value and then i want it to delete all data before that point and if possible i want it to delete the same amount of rows in another variable. I thought about using find(X>1,5) but i dont know how to mark that point and delete everything before that.
I have attached an image of the graph with a point that marks the beginning. Up until that point i want all data deleted.

Jos (10584) on 18 May 2016
% some data
t = 1:15 ;
v = [0 0 0 0 1 2 4 8 4 2 0 -2 -4 -8 -4]
% find the point
i0 = find(abs(v) > 0,1,'first')
% selection
t2 = t(i0:end)
v2 = v(i0:end)
% show result
plot(t,v,'bo:',t2,v2,'r.-')
Christian von Spreckelsen on 18 May 2016
Thanks, this was really helpfull! :)

Ahmet Cecen on 18 May 2016
You can find the point by something along the lines of (you also pay attention to the dimensions of vectors, I didn't):
datacheck = sign(data - threshold); % find all points bigger
highpass = conv([ones(1,5) zeros(4,1)],datacheck); % sum previous 5 points for all points
pointindex = find(highpass==5,1); % find the first point with a sum 5
Then you can erase all points earlier by simply:
data(1:pointindex)=[];

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by