MATLAB does not provide any methods for detecting CD/DVD insertion, nor for ejecting a CD/DVD.
If you are using MS Windows, then you could potentially use ActiveX; https://docs.microsoft.com/en-us/windows/desktop/directshow/eject-method
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!