How to extract single x-value given y threshold

2 vues (au cours des 30 derniers jours)
Dane Dewees
Dane Dewees le 14 Août 2018
Commenté : Dane Dewees le 15 Août 2018
I want to extract x when y is set to a threshold (i.e., if y >= 1.5e12...). Reference the attached image. Essential the x1, and y1 will be fed into my function, it will be fitted, and then the output should be a single value (x given y, or the dashed/solid line in the image). New to matlab, so anything helps!
%%Curve fit plotting %%
x1 = timeStamps(1:60); % taking timestamps from 1 - 120 given smoothed y1 values
y1 = smooth(tic_lin(1:60),'sgolay',1);
% Find coefficients for polynomial (order = 4 and 6, respectively)
fitResults1 = polyfit(x1',y1, 7);
% evaluate the fitted y-values
yplot1 = polyval(fitResults1,x1');
% interpolates to find yi, the values of the underlying function Y at the points in the vector or array xi. x must be a vector.
Time_points = interp1(yplot1, x1', yplot1);
figure( 'Name', 'Curvefit1_poly' );
h = plot(x1', y1);%smoothed-points
hold on;
plot(x1', yplot1);%polyfit points
hold on;
plot(Time_points, yplot1, '*r');%interpolated points of x given y
%given y-threshold, output x(corresponding time_point).
broken = false;
while broken == false
if yplot1 >= 2024671226502.99
index = find(yplot1);
xDesired = x1(index);
broken = true;
else
disp("next iteration through");
end
end

Réponse acceptée

jonas
jonas le 14 Août 2018
Modifié(e) : jonas le 14 Août 2018
I always recommend InterX for accurate and precise intersections
Although, in many cases you can just find the first y-value above the threshold.
id=find(y>=thres,1, 'first')
out=x(id)

Plus de réponses (0)

Catégories

En savoir plus sur Fit Postprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by