External Interfaces/API    

Cleaning Up the MATLAB Environment

When you no longer need the serial port object, you should remove it from memory with the delete function.

Before using delete, you must disconnect the serial port object from the device with the fclose function.

A deleted serial port object is invalid, which means that you cannot connect it to the device. In this case, you should remove the object from the MATLAB workspace. To remove serial port objects and other variables from the MATLAB workspace, use the clear command.

If you use clear on a serial port object that is still connected to a device, the object is removed from the workspace but remains connected to the device. You can restore cleared objects to MATLAB with the instrfind function.


  Disconnecting a Serial Port Object Property Reference