MATLAB: Simplify weird path name

dir isdir pwd ls fileparts fullfileMATLAB

if i have a valid pathname like this:
C:\folder\\\\subfolder\.\.\..\..\documents\map\dir\\\..\location\
how can i change that to its simplest form in a simple way?
one way i came up with is
stupidpath='C:\folder\\\\subfolder\.\.\..\..\documents\map\dir\\\..\location\'
currentpath=cd
cd stupidpath
cleverpath = cd
cd currentpath
and another way would be with strrep, strfind, etc. but that is both quite cumbersome. is there another, easy way?

Best Answer

ok, solved myself:
p='C:\folder\\\\subfolder\.\.\..\..\documents\map\dir\\\..\location\'
p=p(p~='.')
p=p(p~='\'|p([2:end end])~='\')