Effacer les filtres
Effacer les filtres

reverse of fnval: evaluate the variable for given value of function

4 vues (au cours des 30 derniers jours)
Yuji Zhang
Yuji Zhang le 27 Déc 2013
Commenté : Yuji Zhang le 28 Déc 2013
Hi everyone~
See the picture. The blue dots are my data. I want to find out at what x values the function drop to -20 (red circles). Is there something that I can use to do this?
It feels like a reverse of fnval. Using fnval, we find out f(x) for a given x, based on interpolation. Now I want to find out x for a given f(x).
Any help's appreciated. Thanks a lot~ Happy holidays~

Réponse acceptée

Amit
Amit le 27 Déc 2013
Modifié(e) : Amit le 27 Déc 2013
If you have the plot in matlab, that means you must have (x,f(x)) data to begin with. If this is the only data set you are looking for then one simplest thing that can be done is using 'data cursor' on the figure to find out the the values for (x,f(x)) before and after the -20 threshold and then use linear interpolation to approximate the value of x at which f(x) = -20.
Another automated way would be
fzero(@(a) interp1(x,f(x),a,'spline')- (-20),a0)
where a0 is the guess value.
  1 commentaire
Yuji Zhang
Yuji Zhang le 28 Déc 2013
Hi Amit~
Thanks a lot for your help~
Yeah, I was thinking of the way of manually finding the value too. We can write a script to do this.
But the one-line code you provide is so much neater! Nice, it's smart to use 'fzero'. Thanks a lot~ I'll try it out.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by