[Solved] Why savepath resets userpath in Matlab?


I could not maintain stably the userpath in the system so a solution which works in the beginning of the functions

checkSystemMemory();    
%% TODO Virtual memory; enable virtual memory on HDDs.
% http://askubuntu.com/q/799834/25388 

home=char(java.lang.System.getProperty('user.home')); % all systems
if (isempty(userpath))
    userpath(fullfile(home, 'Documents/bin/matlab/') ) 
    % list software locations in the project location
    addpath(fullfile(home, 'Documents/Math/') )
    % list software locations in the centralised location
    addpath(fullfile(home, 'Documents/Programming/Matlab/export_fig-master/') )

    % http://stackoverflow.com/a/38188945/54964
    if ( not( com.mathworks.services.Prefs.getStringPref('CurrentKeyBindingSet') == 'Windows' ) ) 
        com.mathworks.services.Prefs.setStringPref('CurrentKeyBindingSet', 'WindowsDefaultSet.xml')
    end 

    % Event errors else with touchpad scroll
    !synclient HorizTwoFingerScroll=0

    %savepath '/home/masi/pathdef.m'
    savepath(fullfile(home, 'startup.m'));
end

function checkSystemMemory()
%% Java for rdsamp - restart for the change to take effect if necessary.
% https://physionet.org/physiotools/matlab/wfdb-app-matlab/faq.shtml
% http://se.mathworks.com/matlabcentral/answers/92813-how-do-i-increase-the-heap-space-for-the-java-vm-in-matlab-6-0-r12-and-later-versions
% http://stackoverflow.com/a/35971040/54964
isSetHeapSizeMemoryMax = com.mathworks.services.Prefs.getIntegerPref('JavaMemHeapMax');  % MB
if (isSetHeapSizeMemoryMax < 2000)
    com.mathworks.services.Prefs.setIntegerPref('JavaMemHeapMax', 2048); % MB
    fprintf('Quitting Matlab Function because memory %d is insufficient.', ...
         isSetHeapSizeMemoryMax);
    return
end
assert(java.lang.Runtime.getRuntime.maxMemory/1e9 >= 1.9, 'Java heap size too small');

end

solved Why savepath resets userpath in Matlab?