Skip to content

Instantly share code, notes, and snippets.

@ferryzhou
Created March 31, 2012 22:59
Show Gist options
  • Save ferryzhou/2269380 to your computer and use it in GitHub Desktop.
Save ferryzhou/2269380 to your computer and use it in GitHub Desktop.
matlab mkdir if not exist
function mkdir_if_not_exist(dirpath)
if dirpath(end) ~= '/', dirpath = [dirpath '/']; end
if (exist(dirpath, 'dir') == 0), mkdir(dirpath); end
end
@waldyrious
Copy link

For creating a single directory at the level of the script where this code is called, I found it cleaner to use a one-liner, rather than define a function:

if (~exist('<folder_name>', 'dir')); mkdir('<folder_name>'); end%if

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment