Deleting rows until a certain point

조회 수: 24 (최근 30일)
Christian von Spreckelsen
Christian von Spreckelsen 2016년 5월 18일
댓글: Christian von Spreckelsen 2016년 5월 18일
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)
Jos (10584) 2016년 5월 18일
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.-')
  댓글 수: 1
Christian von Spreckelsen
Christian von Spreckelsen 2016년 5월 18일
Thanks, this was really helpfull! :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ahmet Cecen
Ahmet Cecen 2016년 5월 18일
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)=[];

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by