I understand that you are getting an error while trying to execute the code. This kind of issue might arises while there is a naming conflict among the user defined function or variable and in built function or variable.
I notice that in your code you use 'path' as a 2-D matrix. But MATLAB has an inbuilt function 'path' which accepts string. I suspect MATLAB treats your 'path' matrix as 'path' function call and throws an error as it does not get a string as input argument. Try change the name of the matrix 'path' some other variable. You can verify which function/variable is considered by MATLAB by executing the following command in MATLAB command window:
>>which -all path