MATLAB中的变量范围

时间:2014-08-31 16:53:35

标签: matlab

我有以下代码:

function test
s1=1;
s2=-1;
    function inner_test
        s2=1;
        if s1==s2
            display('success')
        end
    end

end

我认为它会显示出成功'但它没有!这是为什么?它与变量范围有关吗?有解决方法吗?

1 个答案:

答案 0 :(得分:3)

你的内心功能永远不会被召唤。试试这个,然后显示success

function test
  s1 = 1;
  s2 = -1;
  function inner_test
    s2 = 1;
    if s1 == s2
      display('success')
    end
  end
  inner_test()
end