确定“gcf”的值在Matlab中
愚蠢、简单的问题 - 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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 callingfh=figure;
it is safer that you use the handle instead ofgcf
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.这比简单的“是”或“否”答案稍微复杂一些。 当前图形的句柄通常会与图形窗口左上角显示的数字匹配,但仅当
'NumberTitle'
图属性 设置为'on'
(默认值)。另一个问题是图形句柄不能保证是整数。有一个
'IntegerHandle'
图属性 确定为图窗创建的句柄是整数还是不可重用的实数。如果此属性设置为'off'
,您将获得非整数的句柄值,因此您打开的第一个数字不会具有句柄 1。例如:并且图形相应地编号:
请注意,当显示图形编号和句柄时,有是数字的某种四舍五入。数字窗口仅显示小数点后 6 位数字。当您更改浮点数的格式时,很明显您正在处理浮点数命令行窗口显示更多小数位:
在这种情况下,显示的图形编号和图形句柄略有不同。
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:And the figure is numbered accordingly:
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:
In this case, the displayed figure number and the figure handle differ slightly.
是的,
gcf
将返回当前选定(或活动)的图形。从文档来看,但还要记住:
使图形“当前”的一种方法是:
另一种方法是使用图形句柄。即,如果您将该图窗称为
h=figure;
,则figure(h)
会将其设为当前图窗。Yes,
gcf
will return the handle of the currently selected (or active) figure. From the documentation,But also remember that:
One way to make a figure "current" is:
Another way is to use the figure handle. i.e., if you called the figure as
h=figure;
, thenfigure(h)
will make it the current figure.