필터 지우기
필터 지우기

Find X of corresponding Y which is manipulated?

조회 수: 1 (최근 30일)
Sagar Dhage
Sagar Dhage 2014년 7월 16일
댓글: Andrei Bobrov 2014년 7월 16일
i need to extract the exact values where the increasing and decreasing trend starts.
I have Fx (column vector) and corresponding T values (column vector). step 1: the values which are less than 100, converts into 0
Fx(Fx <100)= 0;
step2: Fx(diff(Fx)==0) = []; % delete the element which is repeating
step3:B = [0; diff(Fx)]; %difference between element It will start with the first element in the matrix and then report the difference between that and the next element. There's no leading element before the first one so is just truncates the matrix by one element. We add a zero because there is no change there as it's the starting element.
step4: Result = find(B(1:end-1).*B(2:end)<0); This will return the index where you are on the cusp of the inflection. In this case it will be.
step5: New_Fx=Fx(Result); gives the Fx values where trends get changed
Now how to find corresponding T values? I tried New_T=T(New_Fx); but not it showing wrong T values. I think we have removed the elements in Fx which are repeating but not corresponding T values.
How to find these T values to corresponding New_Fx?
complete code is: Fx(Fx <100)= 0;
Fx(diff(Fx)==0) = [];
B = [0; diff(Fx)]; Result = find(B(1:end-1).*B(2:end)<0); New_Fx=Fx(Result);

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 7월 16일
편집: Andrei Bobrov 2014년 7월 16일
[~,i1] = findpeaks(Fx);
[~,i2] = findpeaks(-Fx);
out = T(sort([i1;i2]));
without findpeaks:
ll = find([true;diff(Fx)~=0]);
F = Fx(ll);
b = diff(F);
lll = [false;b(1:end-1).*b(2:end)<0;false];
out = T(ll(lll));
ADD
complete code:
x = xlsread('book3.xlsx');
xx = x(:,2);
xx(xx <100)= 0;
[~,i1] = findpeaks(xx);
[~,i2] = findpeaks(-xx);
out = x(sort([i1;i2]),1);
  댓글 수: 2
Sagar Dhage
Sagar Dhage 2014년 7월 16일
Thanks Andrei for your effort. But it not working properly. I am attaching data file and script file.
complete code is:
x=xlsread('book3.xlsx'); save book3.mat x; load book3 T=x(:,1); Fx_all=x(:,2);
Fx=Fx_all;
Fx(Fx <100)= 0;
Fx(diff(Fx)==0) = [];
B = [0; diff(Fx)]; Result = find(B(1:end-1).*B(2:end)<0); New_Fx=Fx(Result);
[~,i1] = findpeaks(New_Fx); [~,i2] = findpeaks(-New_Fx); out = T(sort([i1;i2]));
Andrei Bobrov
Andrei Bobrov 2014년 7월 16일
see my answer after 'ADD'

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by