如何检查八度中是否定义了变量? [英] How to check if a variable is defined in Octave?

查看:71
本文介绍了如何检查八度中是否定义了变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写加载数据的脚本时,浪费时间等待每次加载.

When writing a script that loads data, it's a waste of time to wait for it to load each time.

如何检查变量是否已定义?

How to check to see if the variable is defined?

推荐答案

您可以使用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:

if (exist("your_var_name", "var") == 1)
    printf("varname exists");
else
    printf("varname not exists");
endif

您可以参考以下链接以获取详细信息:

You may refer the following links for detailed information:

  • Built-in Function: exist (name, type)
  • Status of Variables

这篇关于如何检查八度中是否定义了变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆