This function writes a startup.m file in the userpath, adding RAVEN (and all subdirectories) to the path each time Matlab is started. This function is useful if the user has no rights to save paths to the pathdef.m file in the matlabroot, for instance due to a lack of admin rights. As the startup.m file in the userpath automatically runs with each Matlab start, the paths are automatically loaded. overwrite logical, whether startup.m in the userpath should overwritten (otherwise the RAVEN paths are appended) (optional, default true)
0001 function addRavenToUserPath(overwrite) 0002 % This function writes a startup.m file in the userpath, adding RAVEN (and 0003 % all subdirectories) to the path each time Matlab is started. 0004 % This function is useful if the user has no rights to save paths to the 0005 % pathdef.m file in the matlabroot, for instance due to a lack of admin 0006 % rights. As the startup.m file in the userpath automatically runs with 0007 % each Matlab start, the paths are automatically loaded. 0008 % 0009 % overwrite logical, whether startup.m in the userpath should 0010 % overwritten (otherwise the RAVEN paths are appended) 0011 % (optional, default true) 0012 0013 if nargin<1 0014 overwrite=true; 0015 end 0016 0017 % Get current RAVEN directory 0018 ravenDir=findRAVENroot(); 0019 0020 % Lists all subdirectories 0021 subpath=regexp(genpath(ravenDir),pathsep,'split'); 0022 % Remove .git and doc folders 0023 pathsToKeep=cellfun(@(x) isempty(strfind(x,'.git')),subpath) & cellfun(@(x) isempty(strfind(x,'doc')),subpath); 0024 % Only keep useful paths 0025 subpath = subpath(pathsToKeep); 0026 subpath = subpath(1:end-1); % Remove last entry, is empty field 0027 0028 % Write startup.m file 0029 if overwrite 0030 fid=fopen(fullfile(userpath,'startup.m'),'w'); 0031 fprintf(fid,'%sn','%%% RAVEN path'); 0032 else 0033 fid=fopen(fullfile(userpath,'startup.m'),'a'); 0034 fprintf(fid,'n%sn','%%% RAVEN path'); 0035 end 0036 fprintf(fid,'%sn',strcat('addpath(''',subpath{1},''',...')); 0037 for i=2(length(subpath)-1) 0038 fprintf(fid,'t%sn',strcat('''',subpath{i},''',...')); 0039 end 0040 fprintf(fid,'t%s',strcat('''',subpath{length(subpath)},''');')); 0041 fclose(fid); 0042 end