Why does MATLAB 6.5 (R13) give an Assertion Failure when I try to index into a matrix with zero from my MATLAB function?

2 次查看(过去 30 天)
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 test
alpha = 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:N
a(fix(rand*200)) = 1;
end
error = 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]

采纳的回答

MathWorks Support Team
This bug has been fixed for Release 14 (R14). For previous releases, please read below for any possible workarounds:
This is a bug in MATLAB 6.5 (R13) that has been reported to our development staff for further investigation. This bug is caused by the MATLAB Accelerator.
To work around the problem, you can turn off the MATLAB Accelerator with the following command:
feature jit off
MATLAB will then error out instead of giving an Assertion Failure. This will make it more obvious as to where the erroneous code lies.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by