Assuming you created the serial port object s as in this example, then to close it
fclose(s)
However, sometimes you can accidentally lose the port (e.g. clear, overwrite, change scope, etc...), and fclose(s) will no longer work. The solution is easy
fclose(instrfindall)
More info at instrfin...