Why do I receive a segmentation violation if I use a global structure variable, passed to a function using the ASSIGNIN function, in an anonymous function in MATLAB 7.0.1 (R14SP1)?

If a structure is used in an anonymous function that is passed to the workspace using the ASSIGNIN function with the 'WS' parameter set to 'caller', the anonymous function results in a segmentation violation. The following code reproduces this issue:
function foo
initVars;
temp= @(x) ((CONSTANTS.one / CONSTANTS.two) * x); %This line produces the segmentation violation
end
function initVars
global CONSTANTS
CONSTANTS.one=1;
CONSTANTS.two=2;
assignin('caller','CONSTANTS',CONSTANTS)
end
The stack trace of the segmentation violation is below:
Stack Trace:
[0] m_interpreter.dll:_inDoesArrayExist(0, 0, 0, 0) + 6 bytes
[1] m_interpreter.dll:struct mxArray_tag * __cdecl matrefarg(int)(0, 0, 37, 2623304) + 30 bytes
[2] m_interpreter.dll:_inMatRefDispatch(27, 0, 1, 0x0f7f1300) + 498 bytes
[3] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *)(1, 35, 3, 0) + 4115 bytes
[4] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *)(1, 35, 2, 0) + 272 bytes
[5] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x0f879730, 0, 0, 0x00
<snip>

 채택된 답변

This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
There is a bug in MATLAB 7.0.1 (R14SP1) in the way that anonymous functions cause segmentation violations when using global structures from the ASSIGNIN function.
There are no known workarounds.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

제품

릴리스

R14SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by