Tuesday, February 12, 2013

Matlab: How to get the right bar for Windows and UNIX systems

Windows systems use the backslash bar "\" to separate folders in a path string, while, on the other hand, the normal slash "/" is the one used on Mac OS X/Linux (in general unix) systems.
Even if it's not a big deal since Matlab can handle it, I find it quite disturbing so I wrote this simple code to address the issue.


function [bar]=getbar
% [bar]=getos
% bar="/" for unix systems and bar="\" for Windows systems


os=lower(getenv('OS'));

if (isempty(findstr(os, 'windows')))
    %It's a unix system
    bar="/";
else
    % It's a Windows system
    bar="\";
end


No comments:

Post a Comment

Your comment will be visible after approval.