2013-03-28 16 views
1

我試圖定義一個子功能foo的一個符號變量(見下文)如何在matlab的子函數中定義符號變量?正在獲取:「嘗試將」bar「添加到靜態工作區。」

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(); 

會感謝任何幫助理清以上內容

回答

1

只需跳過syms函數即可。它使用assignin來輸出在運行時不允許嵌套函數的參數。嘗試:

function [ ] = test2() 

foo(); 

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

end 

輸出:

2*bar 
相關問題