日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Matlab R2007a中Warning: Duplicate directory na...

 等緣708 2012-06-10
Matlab R2007a中Warning: Duplicate directory name(轉(zhuǎn))
2012-04-04 15:47
轉(zhuǎn)載自 necrohan
最終編輯 necrohan
自從增加了個路徑后就一直出現(xiàn)這個警告,次數(shù)多了的確讓人感覺很不爽。
搜索后90%的帖子引用了Matlab網(wǎng)站的savepath.m附件,可惜已經(jīng)不能下載了。還好有把這個文件原封不動保留下來的,按順序修改后OK。特轉(zhuǎn)貼此處。
http://hi.baidu.com/zxhathust/blog/item/cc94e3fb2736ba62024f5619.html/cmtid/e34f1b1ccfa1648286d6b622

Matlab R2007a 中存在保存路徑的 Bug,癥狀如下:

當(dāng)你修改了(增加或刪除)搜索路徑,并 savepath 后。以后每次啟動 MATLAB ,會在 Command Window 的第一行顯示下面信息:

Warning: Duplicate directory name: C:\Documents and Settings\c_c\My Documents\MATLAB.

而我們 File --> Set Path,進(jìn)入路徑設(shè)置對話框,在“MATLAB search path:”欄里可以看到只有一個上面提示中的目錄,而并沒有重復(fù)的目錄。但卻每次都提示這個 Warning,至少這會讓你感覺很不爽。

一、Bug出處

事實(shí)上,造成上面的原因并不是真的多了一個提示中的目錄,而是我們修改路徑后

保存設(shè)置時出了問題(命令savepath存在bug!),問題就出在這個savepath.m文件上。

我們在 Matlab 的官網(wǎng)上也可以看到這個 bug 信息,如下:

如上所述,這個bug 存在于 Matlab R2007a 上,到了版本 R2007b 已經(jīng)得到解決。

二、解決辦法

官網(wǎng)上同時也給出了問題的解決辦法,如下:
Exit MATLAB.


Download the attached savepath.m file to replace the existing savepath.m at
matlabroot\toolbox\matlab\general\savepath.m
where matlabroot is the directory in which MATLAB is installed, which you can determine by running the matlabroot function in MATLAB.
Start MATLAB from the Windows desktop shortcut or from Windows Start > Programs.
Run savepath in the Command Window.

The warning should no longer appear.
如上所述,按以下步驟可解決此 bug :

1)下載修正后的 savepath.m 文件 (點(diǎn)擊此處下載savepath.m

2)如果你正在運(yùn)行 Matlab,退出 Matlab

3)假如你的 Matlab 安裝在目錄 D:\Program Files\MATLAB 下,則進(jìn)入目錄

D:\Program Files\MATLAB\R2007a\toolbox\matlab\general 找到并刪除這里的 savepath.m 文件,

4)將(1)步中下載的 savepath.m 文件 拷到此目錄。

5)啟動 Matlab,在 Command Window 輸入 savepath 命令即可解決此問題

6)再次重起 Matlab,那個討厭的 Warning 即會消失

其實(shí)不用到其網(wǎng)站下載,savepath.m 文件內(nèi)容為(在那個文件夾下把下面的內(nèi)容替換原先程序里面的內(nèi)容就可以了):

function notsaved = savepath(outputfile)
%SAVEPATH Save the current MATLAB path in the pathdef.m file.
%   SAVEPATH saves the current MATLABPATH in the pathdef.m
%   which was read on startup.
%
%   SAVEPATH outputFile saves the current MATLABPATH in the
%   specified file.
%
%   SAVEPATH returns:
%     0 if the file was saved successfully
%     1 if the file could not be saved
%
%   See also PATHDEF, ADDPATH, RMPATH, PATH, PATHTOOL.

%   Copyright 1984-2006 The MathWorks, Inc.
%   $Revision: 1.1.4.12.2.1 $ $Date: 2007/02/28 22:06:17 $

% Assume that things are going well until we learn otherwise.
result = 0;

% Unless the user specifies otherwise, we're going to overwrite the
% pathdef.m file that MATLAB currently sees.
if nargin == 0
    outputfile = which('pathdef.m');
else
    if ~ischar(outputfile)
        if nargout == 1
            notsaved = 1;
        end
        return;
    end
end

% This is a token string that we will look for in the template file.
magic_string = 'PLEASE FILL IN ONE DIRECTORY PER LINE';

templatefile = fullfile(matlabroot, 'toolbox', 'local', 'template', 'pathdef.m');

% Try to read the template file. If we can't, that's OK, we have a
% backup plan.
fid = fopen(templatefile, 'r');

if fid ~= -1
    template = fread(fid,'*char')';
    fclose(fid);
else
    template = ['function p = pathdef', 10, ...
                '%PATHDEF Search path defaults.', 10, ...
                '%   PATHDEF returns a string that can be used as input to MATLABPATH', 10, ...
                '%   in order to set the path.', 10, 10, ...
                '% DO NOT MODIFY THIS FILE. IT IS AN AUTOGENERATED FILE.', 10, ...
                '% EDITING MAY CAUSE THE FILE TO BECOME UNREADABLE TO', 10, ...
                '% THE PATHTOOL AND THE INSTALLER.', 10, 10, ...
                'p = [...', 10, ...
                '%%% BEGIN ENTRIES %%%', 10, ...
                magic_string, 10, ...
                '%%% END ENTRIES %%%', 10, ...
                '     ...', 10, ...
                '];', 10, 10, ...
                'p = [userpath,p];', 10];
end

% Find the location of the "magic string" in the file.
magic_index = findstr(template, magic_string);

% Take everything that appears *before* the "magic string" line as
% "firstpart," and everything that appears after that line as
% "lastpart."
% We'll sandwich the path particulars between the two ends.
firstpart = template(1:magic_index-1);
lastpart = template(magic_index + 1:end);

lfs_in_firstpart = find(firstpart == 10, 1, 'last');
firstpart = firstpart(1:lfs_in_firstpart);

lfs_in_lastpart = find(lastpart == 10, 1, 'first');
lastpart = lastpart(lfs_in_lastpart+1:end);

% Read the current path.
thepath = matlabpath;

% First, Break the path down into a cell array of strings, one for
% each entry in the path. We leave the pathsep on the end of each
% string. The path might not actually *end* with a pathsep, but if
% not, we add one for consistency's sake.
ps = pathsep;
if thepath(end) ~= ps
    thepath = [thepath ps];
end

% Get the exact form of the entries that we want to create in the
% new pathdef file based on the path. all_path_lines will be a
% cell array of strings.
all_path_lines_matches = regexp(thepath,['(.[^' ps ']*' ps '?)'],'tokens');
all_path_lines = [all_path_lines_matches{:}]';

% g363196 - For the PC Windows, exclude the value of $documents\MATLAB
% from being saved because it is dynamic (per user) and
% automatically placed on the path by userpath.m on startup.
cname = computer;
if (strncmp(cname,'PC',2))
try
    % What is the current $documents\MATLAB ?
    [rc sd] = dos('startdir $documents\MATLAB -a');
    sd = strcat(sd,';');
    % Exclude it from path list that will be saved
    % Use the indices returned by setdiff to reconstruct the
    % resulting set while preserving the order
    [unused indices] = setdiff(all_path_lines,sd);
    all_path_lines = all_path_lines(sort(indices));
catch
end
end

all_path_lines = matlabrootify(all_path_lines);

% Start constructing the contents of the new file. We start with
% the firstpart.
cont = firstpart;

% Append the paths separated by newline characters
cont = [cont all_path_lines{:}];

% Conclude with the lastpart.
cont = [cont lastpart];

% We have the completed new text of the file, so we try to write it out.
% Return immediately if a directory.
if isdir(outputfile)
    if nargout == 1
        notsaved = 1;
    end
    return;
end
fid = fopen(outputfile, 'w');
if fid == -1
    % We failed to open the file for writing. That might be
    % because we don't have write permission for that file. Let's
    % try to make it read-write.
   
    if isunix
        unix(['\chmod 666 ''', outputfile, '''']);
    elseif ispc && ~strncmpi('\\', pwd, 2)
        dos(['attrib -r "', outputfile, '"']);
    end
    % Last chance. Can we write to it? If we fail here, we have
    % no choice but to fail.
    fid = fopen(outputfile, 'w');
    if fid == -1
    result = 1;
   if nargout == 1
    notsaved = result;
   end
   return;
    end
end

% Write it out.
count = fprintf(fid,'%s', cont);
if count < length(template)
    result = 1;
end
fclose(fid);

clear pathdef; %make sure that pathdef gets cleared.
if nargout == 1
notsaved = result;
end

%---------------------------------------------
function dirnames = matlabrootify(dirnamesIn)
% Given a cell array of path entries, this performs two functions:
% (1) If the path entry under consideration is a subdirectory of
% matlabroot, it encodes that information directly into the string.
% Therefore, even if the location of the MATLAB installation is changed,
% pathdef.m will still point to the appropriate location.
% (2) Performs additional formatting.

% If we're on PC, we want to do our comparisons in a case-insensitive
% fashion. Since it also doesn't matter what case the entries are made in,
% we might as well lowercase everything now - no harm done.
if ispc
    mlroot = lower(matlabroot);
    dirnames = lower(dirnamesIn);
else
    mlroot = matlabroot;
    dirnames = dirnamesIn;
end

% Find indices to entries in the MATLAB root. One match must be at the
% start of the entry. Calculate indices to remaining entries, and preserve
% case-sensitivity
mlr_dirs = cellfun(@(x) ismember(1,x),strfind(dirnames,mlroot));
dirnames(~mlr_dirs) = dirnamesIn(~mlr_dirs);

% We'll need to wrap all the entries in strings, so do some quote escaping
dirnames = strrep(dirnames, '''', '''''');

% Replace MATLAB roots with "matlabroot" only at the start of the entry,
% and wrap entires in quotes. Be sure to escape backslash in mlroot since it
% is a metacharacter to regexprep.
dirnames(mlr_dirs) = regexprep(dirnames(mlr_dirs),strrep(mlroot,'\','\\'),'     matlabroot,''','once');
dirnames(~mlr_dirs) = strcat('     ''',dirnames(~mlr_dirs));
dirnames = strcat(dirnames, ''', ...', {char(10)});


    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多