1

我正在尝试在子函数 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();

将不胜感激任何帮助整理上述

4

1 回答 1

1

跳过这个syms功能。它用于assignin在运行时输出嵌套函数不允许的参数。尝试:

function [ ] = test2( )

foo();

     function [] = foo ()
         bar = sym('bar');
         disp(bar+bar);
     end

end

输出:

2*bar
于 2013-03-28T23:40:26.817 回答