Error using assignin in a nested m function
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (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 Kommentar
Steven Lord
am 14 Nov. 2025
Kategorien
Mehr zu Symbolic Variables, Expressions, Functions, and Settings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!