필터 지우기
필터 지우기

How do i get both values of x for y=3.5

조회 수: 1 (최근 30일)
Kalyan Dash
Kalyan Dash 2018년 2월 10일
답변: Walter Roberson 2018년 2월 17일
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.
Result
xtarget =
2.3660

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 17일
[sorted_difference, sort_index] = sort(abs(y-target));
xtarget = sort(x(sort_index(1:2)));

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by