If you have Computer Vision System toolbox you can use vision.EdgeDetector
System object. If you have edge detector block then you already have this toolbox. This object supports code generation. The default edge detector method it uses is 'Sobel'. When you generate code for this object remember to set all properties using constructor arguments. You may not be able to change properties after construction when generating code.
edgeObj = vision.EdgeDetector;
edges = step(edgeObj, inputImage);