确定“gcf”的值在Matlab中

发布于 2024-11-10 01:15:38 字数 98 浏览 0 评论 0原文

愚蠢、简单的问题 - matlab 中的 gcf 值总是活动图形的图形编号吗?即,如果我正在处理图 5,gcf 是否总是返回 5

Stupid, simple question - is the value of gcf in matlab always going to be the figure number of the active figure? I.e., if I'm working on Figure 5, will gcf always return 5?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄人书 2024-11-17 01:15:38

GCF 返回“当前图窗”的句柄。这始终是活动人物的人物编号。但是,如果您同时单击其他图形,则该图形将变为活动状态。因此,如果您已经知道正在使用的数字,因为您通过调用 figure(5) 将句柄强制为 5,或者因为您通过调用 在变量中捕获了句柄fh=figure; 每当您想要修改图形时,使用句柄而不是 gcf 会更安全,以避免无意中使另一个图形处于活动状态的风险。

另外,如果当前没有打开的图窗,gcf 将打开一个新图窗。

GCF returns the handle of the "current figure". This is always the figure number of the active figure. However, if you click on a different figure in the meantime, that other figure will become active. Thus, if you already know what figure you're working with, because you either forced the handle to 5 by calling figure(5), or because you captured the handle in a variable by calling fh=figure; it is safer that you use the handle instead of gcf whenever you want to modify the figure to avoid risking to inadvertently making another figure active.

Also, if there is no figure currently open, gcf will open a new figure.

独自唱情﹋歌 2024-11-17 01:15:38

这比简单的“是”或“否”答案稍微复杂一些。 当前图形的句柄通常会与图形窗口左上角显示的数字匹配,但仅当 'NumberTitle' 图属性 设置为 'on'(默认值)。

另一个问题是图形句柄不能保证是整数。有一个 'IntegerHandle' 图属性 确定为图窗创建的句柄是整数还是不可重用的实数。如果此属性设置为'off',您将获得非整数的句柄值,因此您打开的第一个数字不会具有句柄 1。例如:

>> hFigure = figure('IntegerHandle','off')  %# The only window open

hFigure =

  173.0040

并且图形相应地编号:

在此处输入图像描述

请注意,当显示图形编号和句柄时,有是数字的某种四舍五入。数字窗口仅显示小数点后 6 位数字。当您更改浮点数的格式时,很明显您正在处理浮点数命令行窗口显示更多小数位:

>> format long
>> hFigure

hFigure =

    1.730040283203125e+002

在这种情况下,显示的图形编号和图形句柄略有不同。

This is a little more complicated than a simple "yes" or "no" answer. The handle for the current figure will generally match the number displayed at the top left of the figure window, but this number is only displayed when the 'NumberTitle' figure property is set to 'on' (the default).

Another wrinkle is that the figure handle is not guaranteed to be an integer. There is an 'IntegerHandle' figure property which determines if the handle created for the figure is an integer or a non-reusable real number. If this property is set to 'off', you get handle values that aren't integers, so the first figure that you open won't have a handle of 1. For example:

>> hFigure = figure('IntegerHandle','off')  %# The only window open

hFigure =

  173.0040

And the figure is numbered accordingly:

enter image description here

Notice that when the figure number and handle are displayed, there is some round-off of the number. The figure window only displays 6 digits past the decimal place. It becomes apparent that you're dealing with floating point numbers when you change the format of the Command Window to show more decimal places:

>> format long
>> hFigure

hFigure =

    1.730040283203125e+002

In this case, the displayed figure number and the figure handle differ slightly.

荒岛晴空 2024-11-17 01:15:38

是的, gcf 将返回当前选定(或活动)的图形。从文档来看,

H = GCF 返回当前图窗的句柄。目前的
图是图形命令(如 PLOT)的窗口,
TITLE、SURF等都会绘制。

但还要记住:

当前图形不一定是最前面的图形
屏幕。

使图形“当前”的一种方法是:

单击图形中包含的 uimenus 和 uicontrols,
或单击图形的绘图区域会导致
数字成为当前。

另一种方法是使用图形句柄。即,如果您将该图窗称为 h=figure;,则 figure(h) 会将其设为当前图窗。

Yes, gcf will return the handle of the currently selected (or active) figure. From the documentation,

H = GCF returns the handle of the current figure. The current
figure is the window into which graphics commands like PLOT,
TITLE, SURF, etc. will draw.

But also remember that:

The current figure is not necessarily the frontmost figure on
the screen.

One way to make a figure "current" is:

Clicking on uimenus and uicontrols contained within a figure,
or clicking on the drawing area of a figure cause that
figure to become current.

Another way is to use the figure handle. i.e., if you called the figure as h=figure;, then figure(h) will make it the current figure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文