Why does MATLAB 6.5 (R13) give an Assertion Failure when I try to index into a matrix with zero from my MATLAB function?
I have the following code:
function testalpha = 0.1;N = 10;wtarget = rand(200,1);w = zeros(200,1);lastval = 0;for i=1:100% make random a vector with N ones
a = zeros(200,1);for c=1:Na(fix(rand*200)) = 1;enderror = a'*wtarget - a'*w;w = w + alpha/N*a*error;val = (wtarget-w)'*(wtarget-w)disp( val-lastval )lastval = val;end
If I run this code in MATLAB, I get the following crash:
----------- Assertion detected at Wed Dec 18 17:20:39 2002 ----------- Assertion failed: hdr->in_use != 0, at line 1218 of file ".\mwmem.c". Attempt to free previously freed memory Configuration: MATLAB Version: 6.5.0.180913a (R13) Operating System: Microsoft Windows 2000 Window System:Version 5.0 (Build 2195: Service Pack 2) Processor ID: x86 Family 6 Model 8 Stepping 6, GenuineIntel Virtual Machine:Java 1.3.1_01 with Sun Microsystems Inc. Java HotSpot(TM) Client VM (mixed mode) Stack Trace: [0] matlab.exe:_mnSignalHandler(0xffffffff, 0, 0, 1) + 592 bytes [1] matlab.exe:void __cdecl ThrowAssertion(void)(0, 0x7a748ba0, 0x65737341, 0x6f697472) + 162 bytes [2] matlab.exe:void __cdecl MATLABAssertFcn(char const *,char const *,int,char const *)(0x7a741868 ": hdr->in_use != 0,", 0x7a74100c ".\mwmem.c", 1218, 0x7a741938 "Attempt to free previously freed..") + 131 bytes [3] libut.dll:_ut_assertstr(0x7a741868 ": hdr->in_use != 0,", 0x7a74100c ".\mwmem.c", 1218, 0x7a741938 "Attempt to free previously freed..") + 25 bytes [4] libut.dll:_mw_free(0x18d93010, 2, 0x18f0e4f8, 0x00dfc8bc) + 542 bytes [5] libut.dll:_utFree(0x18d93010, 0x18f0e4f8, 0x18f0e4f8, 0x00dfc8d8) + 25 bytes [6] libmx.dll:_mxDestroyArrayContents(0x18f0e4f8, 0x18f0e4f8, 0xfffffff7, 0x18f0e4f8) + 209 bytes [snip]
Best Answer