How to find x values from y value in "fit" function?
28 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Kanan Yagublu
il 10 Mag 2022
Commentato: Kanan Yagublu
il 11 Mag 2022
Hi, I have some data and with this data I create a fit function:
f = fit(x,y,'smoothingspline');
plot(f,x,y);
I need to find X values in two points like in the picture. 

I tried to use :
z = x(y==y_i);
But what I get is:
0×1 empty double column vector
How can I solve this problem?
Thanks in advance
0 Commenti
Risposta accettata
Più risposte (1)
Steven Lord
il 10 Mag 2022
Set up a sample polynomial fit.
x = randn(10, 1);
y = (x-1).*(x+1); % polynomial is y = x^2-1 = (x-1)*(x+1)
p = fit(x, y, 'poly2')
Find the points where p takes on the value y = 3.
plusOneSolution = fzero(@(x) p(x)-3, 1)
minusOneSolution = fzero(@(x) p(x)-3, -1)
Check that evaluating the fit at those two points gives us the value y = 3.
check = p([plusOneSolution, minusOneSolution])
0 Commenti
Vedere anche
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!