MATLAB: Do I receive a Segmentation violation when I pass a cell array containing empty matrices to the REGEXP function in MATLAB 6.5 (R13)

arraycellcrashemptyMATLABmatrixregexpregexpiregexprepsegmentationsegvviolation

Why do I receive a Segmentation violation when I pass a cell array containing empty matrices to the REGEXP function in MATLAB 6.5 (R13)?
When I input a cell array of strings containing empty matrices into the REGEXP function, I receive a segmentation violation.For example, the following lines of code:
aaa{1,1} = 'one';
aaa{1,2} = 'two';
aaa{3,1} = 'five';
aaa{3,2} = 'six';
regexp(aaa([1 3],:),'wo') % This works
regexp(aaa,'wo')% This doesn't
returns the following error:
---------
Segmentation violation detected at Thu Mar 20 11:43:45 2003
---------
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)
Register State:
EAX = 1a179760EBX = 00000001
ECX = 1a081d08EDX = 00000003
ESI = 00000000EDI = 1a07d020
EBP = 00dfd3d4ESP = 00dfd20c
EIP = 7b00a634FLG = 00010293
Stack Trace:
[0] libmwbuiltins.dll:_bnRegexpFunction(0, 0x00dfd414, 2, 0x00dfd4dc) + 116 bytes
[1] libmwbuiltins.dll:_bnRegexp(0, 0x00dfd414, 2, 0x00dfd4dc) + 26 bytes
[2] m_interpreter.dll:_inExecuteInternalFcn(98, 2, 0, 0) + 1183 bytes
[3] m_interpreter.dll:enum opcodes__cdecl inIntFcn(enum opcodes,int,int,int)(77, 0x01000062, 0, 2) + 90 bytes
[4] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,struct inPcodeNest_tag volatile *)(2, 0, 0, 0x01a339a0) + 2554 bytes
[5] m_interpreter.dll:_inInterPcode(2, 0x00dfdc54, 0, 0) + 193 bytes
[6] m_interpreter.dll:enum inExecutionStatus__cdecl in_local_call_eval_function(int *,struct _m_parser_interface *,struct _pcodeheader *,int *,struct mxArray_tag * * const,enum inDebugCheck)(0, 0x7a87fa78, 0x00dfdc54, 0x00dfdcf8) + 174 bytes
[snip]

Best Answer

This bug has been fixed for Release 14 (R14). For previous releases, please read below for any possible workarounds:
This has been verified as a bug in MATLAB 6.5 (R13) in the way that the REGEXP function handles empty matrices within a cell array.
Currently, to work around this issue, replace all empty matrices in a cell array with null strings before passing the cell array to REGEXP functions.
For example:
for i = 1:prod(size(aaa))
if isempty(aaa{i})
aaa{i} = '';
end
end