How to draw vertical and horizontal line at the center of the screen in matlab?
9 ビュー (過去 30 日間)
古いコメントを表示
Hi. I want to draw cross image.
I wonder How to draw vertical and horizontal line at the center of the screen.
Is there any way to draw line which is center?
回答 (2 件)
Abdolkarim Mohammadi
2020 年 8 月 23 日
If you want to draw vertical or horizontal line in a figure, you can use xline() and yline().
0 件のコメント
Image Analyst
2020 年 8 月 23 日
I don't know if you can do that. I think you can only draw lines within the MATLAB client area, meaning within a certain figure or axes. If you want you can maximize the figure and if you want to draw on that, you can use annotation().
xline() and yline() only draw on an axes and axes usually don't completely fill the figure. But if you have an axes control on your figure and want a line on that you can use them.
Try this:
figure;
% Set up figure properties.
g = gcf;
g.WindowState = 'maximized';
g.Units = 'normalized';
g.NumberTitle = 'off';
% Get rid of tool bar and pulldown menus that are along top of figure.
g.ToolBar = 'none';
g.MenuBar = 'none';
% Give a name to the title bar.
g.Name = 'Demo by ImageAnalyst'
% Draw vertical red line of thickness 3:
xMiddle = [0.5, 0.5]
yAll = [0, 1]
annotation(g, 'line', xMiddle, yAll, 'Color', 'r', 'LineWidth', 3)
% Draw vertical red line of thickness 3:
yMiddle = [0.5, 0.5]
xAll = [0, 1]
annotation(g, 'line', xAll, yMiddle, 'Color', 'r', 'LineWidth', 3)
% xline and yline draw only within an axes, not outside of it into the figure.
% xline(xMiddle, 'LineWidth', 3) % Will create an axes that may not be centered.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/350378/image.png)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dialog Boxes についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!