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>
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Scope Variables and Generate Names についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!