How do i get both values of x for y=3.5
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
x=0:0.001:3.5;
y=5*sin(x);
figure
plot(x,y);
grid ON
target =3.5
[difference, index_At_target] = min(abs(y-target));
xtarget = x(index_At_target)
The result is showing only one output as xtarget=2.3660, where as there are two values of x for same y value. I want to obtain the other value from plot not by solving for y.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170177/image.jpeg)
Result
xtarget =
2.3660
0 commentaires
Réponses (1)
Walter Roberson
le 17 Fév 2018
[sorted_difference, sort_index] = sort(abs(y-target));
xtarget = sort(x(sort_index(1:2)));
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!