为什么savepath在Matlab中重置用户路径? [英] Why savepath resets userpath in Matlab?

查看:296
本文介绍了为什么savepath在Matlab中重置用户路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

条件:userpathaddpathsavepath
失败 差异条件:无法以sudo/root身份启动Matlab 此处
支持: MATLAB不应由超级用户运行-服务台.
设置

Condition: unsuccessful userpath with addpath and savepath
Differential conditions: unable to start Matlab as sudo/root here
Support: MATLAB is not intended to be run by the super user - Service desk.
Settings

echo "export MATLAB_USE_USERWORK=1" >> $HOME/.bashrc    
matlab -nodesktop -nosplash -r \ 
    "userpath('/home/masi/Documents/bin/matlab/'); exit;"

导致userpath为空('')

  • 测试代码1

  • Test code 1

userpath('/home/masi/Documents/bin/matlab/')
home='/home/masi/';
savepath(fullfile(home, 'pathdef.m')); 
% ~/pathdef.m originally but reject because expansion of ~ not working
userpath

输出

'' 

预期输出

'/home/masi/Documents/bin/matlab/:'

在启动Matlab之后,从Matlab的提示中完全重申

Complete reiteration from Matlab's prompt after starting Matlab

>> userpath

ans =

/home/masi/Documents/bin/matlab/:

>> home='/home/masi/';
>> savepath(fullfile(home, 'pathdef.m'));
>> userpath

ans =

     ''

  • 测试代码2

  • Test code 2

    if (userpath == '')
        userpath('/home/masi/Documents/bin/matlab/')
        addpath('/home/masi/Documents/Math/')
        savepath '/home/masi/pathdef.m'
    end
    
    % Visualising path in Home > Environment > Set Path
    

    输出:/home/masi/Documents/Math/留在路径中,但/home/masi/Documents/bin/matlab/不在路径中.预期的输出:都留在路径中.

    Output: /home/masi/Documents/Math/ stays in path, but /home/masi/Documents/bin/matlab/ not. Expected output: both stay in path.

    测试代码3

    % Edit the Matlab preference file as root. [Kusalananda] 
    % My startup.m
    userpath('/home/masi/Documents/bin/matlab/')
    addpath('/home/masi/Documents/Math/')
    savepath '/home/masi/startup.m'
    
    % Visualising path in Home > Environment > Set Path
    

    输出:/home/masi/Documents/Math/留在路径中,但/home/masi/Documents/bin/matlab/不在路径中.预期的输出:都留在路径中.

    Output: /home/masi/Documents/Math/ stays in path, but /home/masi/Documents/bin/matlab/ not. Expected output: both stay in path.

    测试代码4

    % Use MATLABPATH environment variable instead. [Kusalananda] 
    

    如何?

    Matlab:2016a
    系统:Linux Ubuntu 16.04 64位
    硬件:Macbook Air 2013-mid
    相关:在Linux 此处在官方脚本不完整的地方设置wfdb

    Matlab: 2016a
    System: Linux Ubuntu 16.04 64 bit
    Hardware: Macbook Air 2013-mid
    Related: setup wfdb in Linux here where the official script is incomplete

    推荐答案

    我无法在系统中稳定地维护userpath,因此该解决方案可以在功能开始时使用

    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
    

    这篇关于为什么savepath在Matlab中重置用户路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆