# Calculating cross-point within a set of x & y data

18 views (last 30 days)
Sonoma Rich on 20 Jul 2011
I have a set of x & y data that I collected from a test. The plot of the data resembles a mountain with a single peak. Given this set of data, I want to calculate the values for x where y is 98% of the peak (max) value. There are two values for x. Any suggestions.
x =
-0.0004
0.0521
0.1047
0.1573
0.2100
0.2630
0.3152
0.3687
0.4200
0.4753
0.5261
0.5791
0.6313
0.6830
0.7365
0.7896
0.8431
0.8943
0.9474
1.0004
y =
17.9863
18.7457
19.6454
20.7195
21.8660
23.0983
24.7895
26.6830
29.0743
31.8048
35.1163
39.2968
44.3394
51.4311
58.5378
51.3318
42.9399
37.2848
33.2080
30.2815

Sean de Wolski on 20 Jul 2011
[mxy idx] = max(y); %max and index
y98 = 0.98*mxy; %value of y crossing
pt1 = interp1(y(1:idx),x(1:idx),y98); %interp lower value
pt2 = interp1(y(idx:end),x(idx:end),y98); %interp higher value
plot(x,y,'b-',[pt1 pt2],[y98 y98],'gd') %visualize
Edit for multiple x-ings Per comments:
x = cumsum(repmat(x,3,1)); %sample data your x/y from before
y = repmat(y,3,1);
y98 = 0.98*max(y);
yxing = y-y98; %zero the yvalue
ylox = find(diff(sign(yxing))); %crossings
ylox(:,2) = ylox+1; %both sides
ylox = ylox(:);
xvals = reshape(x(ylox),[],2); %set up poits
yvals = reshape(y(ylox),[],2);
n = size(xvals,1);
xings = zeros(n,1);
for ii = 1:n
xings(ii) = interp1(yvals(ii,:),xvals(ii,:),y98); %interp each point
end
plot(x,y,'b-',xings,y98,'gd') %visualzie
Sonoma Rich on 20 Jul 2011
This will work for this data set, but what if the data set had two or three humps (peaks) with multiple cross-points? Any suggestions?

Oleg Komarov on 20 Jul 2011