x and y- line until point

113 次查看(过去 30 天)
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.
.

更多回答(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 中查找有关 Annotations 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by