八度中的全局变量 [英] global variable in octave

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

问题描述

global m = 1;
function p = h()
  m
end
h()

我正在尝试运行此脚本,但出现此错误:

I'm trying to run this script, but I get this error:

'm'在第4行第3列附近未定义

'm' undefined near line 4 column 3

请问我,如何使用函数中的变量?

Say me please, how I can use the variable from functions?

推荐答案

您必须按照以下说明在函数内部声明var:

You have to declare the var also global inside the function as described here: https://www.gnu.org/software/octave/doc/interpreter/Global-Variables.html

global m = 1;
function p = h()
  global m;
  m
endfunction
h()

这篇关于八度中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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