Calculating cross-point within a set of x & y data
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuesta aceptada
Sean de Wolski
el 20 de Jul. de 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
Más respuestas (1)
Oleg Komarov
el 20 de Jul. de 2011
And many other on the FEX if you look for intersection
0 comentarios
Ver también
Categorías
Más información sobre Industrial Statistics en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!