如何检查变量是否在 Octave 中定义?
当编写加载数据的脚本时,每次等待它加载都是浪费时间。
如何检查变量是否已定义?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
当编写加载数据的脚本时,每次等待它加载都是浪费时间。
如何检查变量是否已定义?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您可以使用 Octave 中的
exist
函数来完成这项工作。它可用于检查给定名称作为变量、内置函数、文件或目录是否存在。在您的情况下,要检查变量是否存在,您可以使用类似以下内容:您可以参考以下链接以获取详细信息:
You can use the
exist
function in Octave to do the work. It can be used to check the existence of given name as a variable, built in function, file, or directory. In you case, to check the existence of a variable, you may use something like this:You may refer the following links for detailed information:
还需要将变量名称放在引号中,
exist("varname", "var")
Need to put the variable name in quotes too,
exist("varname", "var")
注意 itemcount 用双引号引起来。
通过更改 == 之后的值,您可以
从 / 更多信息中检查函数名称、文件名、目录、路径等:
https://www.gnu.org/software /octave/doc/interpreter/Status-of-Variables.html#XREFexist
其他返回值..
2 如果名称是绝对文件名、Octave 路径中的普通文件或(附加“.m”后)Octave 路径中的函数文件,3 如果名称是 Octave 路径中的“.oct”或“.mex”文件Octave 的路径,如果名称是内置函数,则为 5;如果名称是目录,则为 7;如果名称是与文件不关联的函数(在命令行中输入),则为 103。否则,返回 0。
Note itemcount is in double quotes.
By changing the value after ==, you can check for function name, file name, dir, path etc.
from / more info at:
https://www.gnu.org/software/octave/doc/interpreter/Status-of-Variables.html#XREFexist
other return values ..
2 if the name is an absolute file name, an ordinary file in Octave’s path, or (after appending ‘.m’) a function file in Octave’s path, 3 if the name is a ‘.oct’ or ‘.mex’ file in Octave’s path, 5 if the name is a built-in function, 7 if the name is a directory, or 103 if the name is a function not associated with a file (entered on the command line). Otherwise, return 0.