You can try out my lineinpolygon.m function. (Sorry, the GitHub repo doesn't have a proper readme yet... you'll need to copy the lineinpolygon.m and inpolygons.m functions to your path).
The function finds the intersection points of the line and the polygon, then determines which resulting line segments are inside and outside the polygon. It does assume the clockwise=external and counterclockwise=internal contour (i.e. hole); most shapefiles follow this convention.
Right now this function uses the Mapping Toolbox polygon functions. I plan to update it to use the newer polyshape objects that were introduced in recent versions, but I haven't found time for that yet.