필터 지우기
필터 지우기

already know function: find x value given y AND plot (x,y) on the same graph

조회 수: 3 (최근 30일)
Can someone help me with this simple question? I already know the function expression. I would like to find the x value corresponding to y=0.37 and plot the point (x,y) with dash lines connecting to x/y axis in the same graph on top of the line for y?
Here is my current code:
x = 0:100000;
y = exp(-x/38190.7);
figure
semilogy(x,y)
grid on
Thank you!

채택된 답변

Star Strider
Star Strider 2016년 2월 6일
This works:
x = 0:100000;
ofst = 0.37;
y = @(x) exp(-x/38190.7); % Create Anonymous Function
xval = fzero(@(x) y(x)-ofst, 1) % Solve For ‘ofst’ Value
figure(1)
plot(x, y(x))
hold on
plot([xval xval], [0 ofst], '--')
plot([0 xval], [ofst ofst], '--')
plot(xval, ofst, 'bp')
hold off
grid
  댓글 수: 5
Kalyan Dash
Kalyan Dash 2018년 2월 6일
The code works fine. Can you please elaborate the code
plot([xval xval], [min(ylim) ofst], '--')
plot([0 xval], [ofst ofst], '--')
plot(xval, ofst, 'bp')
Star Strider
Star Strider 2018년 2월 6일
MATLAB requires two values for the x and two values for y in order to plot the line. It will plot a constant line at a given x or y if both values of either the x or y coordinates are the same value.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by