フィルターのクリア

x and y- line until point

59 ビュー (過去 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 Center および File ExchangeBlue についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by