필터 지우기
필터 지우기

x and y- line until point

조회 수: 60 (최근 30일)
Robin Kleemann
Robin Kleemann 2022년 10월 7일
댓글: Star Strider 2022년 10월 10일
Hello, I want to create a diagram which looks exactly like this. Now I want to have a dashed line in x and y direction up to this point.
with the command xline() and yline() I can only draw lines over the whole plot, does anyone have an idea how to limit this?
Thanks for your help!

채택된 답변

Star Strider
Star Strider 2022년 10월 7일
Illustrating the approach —
x = linspace(0, 5); % Create Data
y = sin(2*pi*x/2.5) + 1.05*x; % Create Data
Rmin = 3.27; % Define Value
ix = find(diff(sign(y-Rmin))); % Find Approximate Index
idxrng = max(1,ix-1) : min(numel(x),ix+1); % Define Index Range
xRmin = interp1(y(idxrng),x(idxrng), Rmin); % X-Coordinate Of Intercept
yRmin = interp1(x(idxrng),y(idxrng), xRmin); % Y-Coordinate Of Intercept
figure
plot(x, y)
hold on
plot([0 xRmin], [1 1]*Rmin, '--r') % Horizontal Dashed Line
plot([1 1]*xRmin, [0 1]*yRmin, '--r') % Vertical Dashed Line
plot(xRmin, yRmin, 'or') % Marker
hold off
grid
text(0,yRmin, 'yR_{min}', 'Horiz','right', 'Vert','middle') % Horizontal Line Axis Label
text(xRmin,0, 'xR_{min}', 'Horiz','center', 'Vert','top') % Vertical Line Axis Label
If you have a vector of the relevant R values, you can put the interp1 calls in a loop and return a vector of the appropriate coordinates. Depending on the initial R values, order the interp1 calls to find the appropriate missing values. The dashed line plot calls can also be in a loop. With respect to , there would be two intercepts of the curve for the time values, so you would have to choose the first one (with the lowest index). The others should be striaghtforward.
If you are starting with the time values in a vector and have the data for the curve, this is much simpler and only requires a single interp1 call to get all the R values.
.
  댓글 수: 2
Robin Kleemann
Robin Kleemann 2022년 10월 10일
perfect, thank you!
Star Strider
Star Strider 2022년 10월 10일
As always, my pleasure!

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

추가 답변 (1개)

Jiri Hajek
Jiri Hajek 2022년 10월 7일
You will neet to plot the auxiliary lines separately - first plot the graph, then use the hold function and last plot all the lines you need. To plot a straight line, you need just the starting and end point.
xline and yline are ment to always span the whole plot area, which simplifies inputs for their plotting.

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by