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

1 次查看(过去 30 天)
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

回答(1 个)

Nawaf Almutairi
Nawaf Almutairi 2018-8-27
hud

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by