What is a segmentation violation?
A segmentation violation is an error that occurs when MATLAB attempts to write to a region of memory to which it does not have access. This usually happens if the source code either writes past the end of an array or dereferences an uninitialized pointer. In the first case, MATLAB only has legal access to the memory regions within the array; the regions past the end of the array may belong to another program or to part of the current program’s executable code. In the latter case, the pointer almost invariably points to a memory region owned by another process.