How to draw vertical and horizontal line at the center of the screen in matlab?

7 次查看(过去 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
If you want to draw vertical or horizontal line in a figure, you can use xline() and yline().

Image Analyst
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.

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by