Deleting rows until a certain point
10 views (last 30 days)
Show older comments
Christian von Spreckelsen
on 18 May 2016
Commented: 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.
0 Comments
Accepted Answer
Jos (10584)
on 18 May 2016
Perhaps this example can help you:
% 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.-')
More Answers (1)
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)=[];
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices 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!