Error using assignin in a nested m function
显示 更早的评论
Error using assignin
Attempt to add "q" to a static workspace.
Error in syms (line 283)
assignin('caller', x, xsym);
Error in mywork/myfunction (line 66)
syms a(t) q
This error occurs when running mywork.m but not myfunction alone.
采纳的回答
更多回答(1 个)
Assignin is something you should generally try to avoid. It has many hazards.
In this case, where myfunction is nested in mywork, it should be especially unnecessary. Just pre-initiliaze q in mywork's workspace (e.g. set it to empty, []). Then, q will automatically be shared with myfunction's workspace as well, see Sharing Variables Between Parent and Nested Functions.
1 个评论
Steven Lord
2025-11-14
类别
在 帮助中心 和 File Exchange 中查找有关 Symbolic Variables, Expressions, Functions, and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!