MATLAB: Dealing with \ and / (windows vs. unix) for path definition.

MATLABunix windows path dir

Hi everybody,
Simple question, let's say I'm using mac osx and some colleagues use windows… and I have to share a matlab script. Problem, this script needs to look in folder to load data files or print figures:
load ./data/data.mat
plot(data(:,1),data(:,2))
print -dpdf ./graph/figure.pdf
this is how it is written on unix system, but on windows I have to replace all the / by \
load .\data\data.mat
Is there a way to deal with that or the only way to make it works on both systems is to add a conditional statement like
if isunix load ./data/data.mat else load .\data\data.mat end
thanks for any help,
cheers
Pieter

Best Answer

Matt's right. You can use forward slashes when making up path strings under Windows versions of MATLAB. It handles them just fine. No need to ever use backslashes. Actually you don't even need filesep. This works just fine as a path:
myMFilesPath = 'D:/MATLAB/work/my m-files'; % Perfectly fine under Windows.