Clear Filters
Clear Filters

How to select thresholds on a XY plot and fit a line btw thresholds

4 views (last 30 days)
Hi there, I have a matrix (test & test1) of vectors that I split into a matrix of X (ANG) values and a matrix of Y (MOM) values. I am plotting XY in a scatter plot. I then want to identify when the slope of the XY plot is changing. Those points will be the thresholds I need.
I want the code to be able to identify thresholds in both cases. This is what I have done:
%%Identify index for 5% and 95% MOM using threshold
Mom5up_indx=zeros(1,length(MOM));
Mom95up_indx=zeros(1,length(MOM));
Mom5down_indx=zeros(1,length(MOM));
Mom95down_indx=zeros(1,length(MOM));
for i=1:length(Mom5)
Mom5up_indx(1,i)= find(MOM(:,i)>=Mom5(1,i),1,'first');
Mom95up_indx(1,i)= find(MOM(:,i)>=Mom95(1,i),1,'first');
Mom5down_indx(1,i)= find(MOM(:,i)>=Mom5(1,i),1,'last');
Mom95down_indx(1,i)= find(MOM(:,i)>=Mom95(1,i),1,'last');
end
%%Identify Linear fit and Slope value for the three segments of the ANG-MOM signal
%Define thresholds
THR1= Mom5up_indx; % First crossing 5% of Max MOM
THR2= ??; % First change in Slope after 5% of Max MoM
THR3= ??; % Second change in Slope after 5% of Max MoM
THR4= Mom95up_indx; % First crossing 95% of Max MOM
THR5= Mom95down_indx; % Last before crossing 95% of Max MOM
THR6= Mom5down_indx; % Last before crossing 5% of Max MOM
% Preallocation of variables
Slope1=zeros(1,length(ANG));
Slope2=zeros(1,length(ANG));
Slope3=zeros(1,length(ANG));
for i=1:length(ANG)
f= fit(ANG([THR1(i):THR2(i)],i),MOM([THR1(i):THR2(i)],i),'poly1');
Slope1(1,i) = f.p1(1);
f1= fit(ANG([THR3(i):THR4(i)],i),MOM([THR3(i):THR4(i)],i),'poly1');
Slope2(1,i) = f1.p1(1);
f2= fit(ANG([THR5(i):THR6(i)],i),MOM([THR5(i):THR6(i)],i),'poly1');
Slope3(1,i) = f2.p1(1);
end
Hope you have all the info you need to help me. Many thanks
Ale
  2 Comments
dpb
dpb on 27 Aug 2018
Instead of (or in addition too) attaching .fig files, how about saving as .jpg and inserting images so folks can see w/o downloading?

Sign in to comment.

Answers (1)

Nawaf Almutairi
Nawaf Almutairi on 27 Aug 2018
hud

Categories

Find more on Particle & Nuclear Physics 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!