Why an I getting a segmentation violation error?
Segmentation violation errors occur when MATLAB tries to write to an area of memory that is not allowed. Some possible causes of this are improper dereferencing of pointers, use of pointers which contain incorrect values, and writing past the end of a dimensioned array. You should check your MEX-file function to see if any of these possibilities are occurring.