Clear Filters
Clear Filters

Find X of corresponding Y which is manipulated?

1 view (last 30 days)
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);

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 16 Jul 2014
Edited: Andrei Bobrov on 16 Jul 2014
[~,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 Comments
Sagar Dhage
Sagar Dhage on 16 Jul 2014
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]));

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!