MATLAB: Do I get a segmentation violation when I index an empty dimension in a matrix with a colon operator in MATLAB 6.1 (R12.1)

colonemptyindexMATLABmatrixsegmentationviolation

Why do I get a segmentation violation when I index an empty dimension in a matrix with a colon operator in MATLAB 6.1 (R12.1)?
When I evaluate the following code:
a=zeros(5,6,0,7);
a(:,2,:,3)=NaN;
The following error results:
------------
Segmentation violation detected at Mon Feb 11 11:47:10 2002
------------
Configuration:
MATLAB Version: 6.1.0.450 (R12.1)
Operating System: Microsoft Windows 2000
Window System:Version 5.0 (Build 2195: Service Pack 1)
Processor ID: x86 Family 6 Model 8 Stepping 6, GenuineIntel
Virtual Machine:Java 1.1.8 from Sun Microsystems Inc.
Register State:
EAX = 02d7cc80EBX = 00000001
ECX = 00000028EDX = 00000005
ESI = 00000000EDI = 00000000
EBP = 0149d074ESP = 0149d068
EIP = 015adab0FLG = 00010246
Stack Trace:
[0] libmx.dll:_indexed8bytecopyfcn(5, 0, 1, 40) + 352 bytes
[1] libmx.dll:_CopyData(0x015ad950, 0, 0x02d7cc80, 0) + 737 bytes
[2] libmx.dll:_mxSubscriptedAssignment(0x01251818, 0, 0x0049d458, 0x02d7cc80) + 899 bytes
[3] m_interpreter.dll:_inMatassnd(0x29251818, 4, 0x0149d458, 0x2924a658) + 152 bytes
[4] m_interpreter.dll:_inMatAssDispatch(0x2924a658, 4, 0x0149dc54, 0x015f685c) + 2089 bytes
[5] m_interpreter.dll:_inInterPcode(2, 0x0149dce0, 0, 0) + 4489 bytes
[6] m_interpreter.dll:_in_local_call_eval_function(0, 0x01a2d840, 0x0149dce0, 0x0149dd74) + 174 bytes
[7] m_interpreter.dll:_inEvalStringWithIsVarFcn(0x1e86d248 "a(:,2,:,3)=NaN;\n", 16, 0, 0) + 340 bytes
[8] m_interpreter.dll:_inEvalString(0x1e86d248 "a(:,2,:,3)=NaN;\n", 16, 0, 0) + 50 bytes
[9] m_interpreter.dll:_inEvalCmdWithLocalReturnandtype(0x1e86d248 "a(:,2,:,3)=NaN;\n", 0, 2, 0x0149dea4) + 68 bytes
[10] m_interpreter.dll:_inEvalCmdNoEnd(0x1e86d248 "a(:,2,:,3)=NaN;\n", 0x5cc9e067, 0, 11) + 16 bytes
[snip]
However, when the code is changed to the following, it works:
a=zeros(5,6,0,7);
a(:,2,1,3)=NaN;

Best Answer

This is a bug in MATLAB 6.1 (R12.1) that has been fixed in MATLAB 6.5 (R13).
There are no known workarounds for MATLAB 6.1.
Assigning to a range of locations (with just the : operator in the dimension with length 0) in an empty array should return an empty array. Using actual ranges of number to index the same dimension, i.e. 1:10, will expand the matrix to the appropriate size, and perform the assignment.