Function Reference
— Built-in Function: [fid, msg] = dup2 (old, new)

Duplicate a file descriptor.

If successful, fid is greater than zero and contains the new file ID. Otherwise, fid is negative and msg contains a system-dependent error message.