Remove serial port object from MATLAB workspace
This example creates the serial port object s on a Windows® platform, copies s to a new variable scopy, and clears s from the MATLAB workspace. s is then restored to the workspace with instrfind and is shown to be identical to scopy.
s = serial('COM1'); scopy = s; clear s s = instrfind; isequal(scopy,s) ans = 1
If obj is connected to the device and it is cleared from the workspace, then obj remains connected to the device. You can restore obj to the workspace with the instrfind function. A serial port object connected to the device has a Status property value of open.