From stack overflow. Actual functions to make code cross-platform.
Of course, if you try to access a Windows-style path on a Mac, it will error.
MATLAB includes a set of functions that make it fairly easy to make your code cross-platform with respect to these sorts of issues. Take a look at, for example, the functions
fullfile
, fileparts
, filesep
, pathsep
, ispc
, and ismac
.