How can I change the length of a line using the xline() function?

25 ビュー (過去 30 日間)
Md Affan
Md Affan 2024 年 7 月 9 日
コメント済み: Umar 2024 年 7 月 9 日
Recently, I was trying to make a graph wihich required a vertical line to be of a specific length (so it stops at a line plot, and not cut through). Coudn't find any functions. How can I do that?
xline([1336.5 648],"r--")
(The part that I want to remove)
  3 件のコメント
Md Affan
Md Affan 2024 年 7 月 9 日
編集済み: Md Affan 2024 年 7 月 9 日
sorry, there was a mistake in my question. it was the length, not width :/
Umar
Umar 2024 年 7 月 9 日
It’s okay, Md. Sounds like your problem is resolved. Good luck with your project. If you still have any further questions, we are still here to help you out.

サインインしてコメントする。

採用された回答

Sam Chak
Sam Chak 2024 年 7 月 9 日
Since you know the coordinates, you can directly use the plot() function.
% plot([x1, x2], [y1, y2]) creates a line between (x1, y1) and (x2, y2)
plot([1336.5 1336.5], [350 648], 'r--'), ylim([350 700]), grid on
  6 件のコメント
Sam Chak
Sam Chak 2024 年 7 月 9 日
@Md Affan, Maybe you forgot to divide by 255.
myColor = [126, 47, 142]; % color for violet
plot([1336.5 1336.5], [350 648], '--', 'color', myColor/255)
ylim([350 700]), grid on
Umar
Umar 2024 年 7 月 9 日
Thanks for your contribution towards this problem, @Sam.

サインインしてコメントする。

その他の回答 (1 件)

Shreshth
Shreshth 2024 年 7 月 9 日
Dear Affan,
I can see that you are trying to introduce vertical lines in your graph with specific X and Y values.
There is not a direct line functionality that provides control over the vertical plot for your use case but one way of doing it is by using discrete data plots like "Stem Plots". You can find the functions associated with it in the following MathWorks documentation link, http://www.mathworks.com/help/matlab/stem-and-stair-plots.html.
Hope it helps.
  1 件のコメント
Umar
Umar 2024 年 7 月 9 日
Also, thanks for your help as well, Shreshth.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by