dealing with \ and / (windows vs. unix) for path definition.
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (3)
You can use the FILESEP command. However, are you sure it's necessary? I always seem to remember MATLAB being smart enough to parse directory path strings correctly regardless of which separator you use.
1 Commento
Sean de Wolski
il 21 Feb 2014
Also, fullfile
pieter vandromme
il 21 Feb 2014
Modificato: pieter vandromme
il 21 Feb 2014
1 voto
1 Commento
Image Analyst
il 21 Feb 2014
Modificato: Image Analyst
il 21 Feb 2014
I'm not sure what the middle sentence means, but your final sentence that says you can always use /, and never use \, regardless of platform/OS is correct.
jim bob
il 2 Mar 2020
Sometimes a function (such as unzip) will return filenames in the format appropriate for the platform you are using so you may need to convert from one system to another.
path_pc = '\path\to\folder';
%convert to a unix version:
path_unix = path_pc;
path_unix(strfind(path_unix,'\'))='/';
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!