我正在尝试在子函数foo中定义一个符号变量(见下文)
function [ ] = test2( )
foo();
function [] = foo ()
syms bar;
end
end
我收到以下错误,并且不确定如何解决此问题:
EDU>> test2
Error using assignin
Attempt to add "bar" to a static workspace.
See MATLAB Programming, Restrictions on Assigning to Variables for
details.
Error in syms (line 66)
assignin('caller',x,sym(x));
Error in test2/foo (line 6)
syms bar;
Error in test2 (line 3)
foo();
感谢您解决上述问题的任何帮助
答案 0 :(得分:1)
跳过syms
功能。它使用assignin
输出运行时不允许嵌套函数的参数。尝试:
function [ ] = test2( )
foo();
function [] = foo ()
bar = sym('bar');
disp(bar+bar);
end
end
输出:
2*bar