MATLAB: Genpath subfolders slash the wrong way

genpathMATLABMATLAB Parallel ServerParallel Computing Toolbox

Hi,
I am using the parallel toolbox to run code that has been developed on a Mac on a Unix cluster. I am using Windows 10 and want to set up the code from my machine to run on the Unix cluster.
The code starts to run locally like this:
%% Set Cluster
% Get a handle to the cluster
c = parcluster;
%define username
username = 'lf';
% Create a list of all the paths in repo and supplement it so that the
% files would be on path and could be read on Cluster
localPath1 = genpath(strcat('/Users/',username,'/Documents/MATLAB/repo/data'))
Having removed the ; after localPath1, I got:
localPath1 =
'/Users/lf/Documents/MATLAB/repo/data;\Users\franssel\Documents\MATLAB\repo\data\XXX'
This, I believe, makes the code buggy as it runs as the paths with different / vs \ throws error messages.
Just FYI: The code continues by replacing the local path by the remote path, i.e. like this if we had only 1 localPath (there are more in the real code):
cellLocalPath{1} = strrep(cellLocalPath{i},strcat('/Users/',username,'/Documents/MATLAB/'),strcat('/YYY/home/',username,'/'))
I am grateful on any advice on how to deal with this as I could not find a solution online.
Thank you and best wishes,
Linnéa

Best Answer

Try this:
localPath1 = strrep(localPath1, '\', '/');