4

当我进入

edit somenewfile.m

在我的 Matlab R2010a 命令窗口中,它给了我这个错误

??? Error using ==> edit at 57
Neither 'somenewfile' nor 'somenewfile.m' could be found.

在我的另一台运行 R2012a 的计算机上,同样的命令可以工作并创建一个新文件。2010年有什么不同吗?

我试着摆弄 edit.m 了一会儿,但我担心我会搞砸一些事情。这是它失败的部分

try
if (nargin == 0)
    openEditor;
else
    for i = 1:nargin
        argName = translateUserHomeDirectory(strtrim(varargin{i}));
        if isempty(argName)
            openEditor;
        else
            checkEndsWithBadExtension(argName);

            if ~openInPrivateOfCallingFile(argName)
                if ~openOperator(argName)
                    if ~openWithFileSystem(argName, ~isSimpleFile(argName))
                        if ~openPath(argName)
                            showEmptyFile(argName);
                        end
                    end
                end
            end
        end
    end
end
catch exception
    throw(exception); % throw so that we don't display stack trace
end

在 ShowEmptyFile 而看起来像

%--------------------------------------------------------------------------
% Helper function that displays an empty file -- taken from the previous edit.m
% Now passes error message to main function for display through error.
function showEmptyFile(file)
errMessage = '';
errID = '';

% If nothing is found in the MATLAB workspace or directories,
% open a blank buffer only if:
%   1) the given file is a simple filename (contains no qualifying 
%      directories, i.e. foo.m) 
%   OR 
%   2) the given file's directory portion exists (note that to get into 
%      this method it is implied that the file portion does not exist)
%      (i.e. myDir/foo.m, where myDir exists and foo.m does not).
[path fileNameWithoutExtension extension] = fileparts(file);

if isSimpleFile(file) || (exist(path, 'dir') == 7)

    % build the file name with extension.
    if isempty(extension) 
        extension = '.m';
    end
    fileName = [fileNameWithoutExtension extension];

    % make sure the given file name is valid.
    checkValidName(fileName);

    % if the path is empty then use the current working directory.
    % else use the fully resolved version of the given path.
    if (strcmp(path, ''))
       path = pwd;
    else
        whatStruct = what(path);
        path = whatStruct.path;
    end

    if (isempty(checkJavaAvailable) ...
            && com.mathworks.mde.editor.EditorOptions.getShowNewFilePrompt == false ...
            && com.mathworks.mde.editor.EditorOptions.getNamedBufferOption == ...
                com.mathworks.mde.editor.EditorOptions.NAMEDBUFFER_DONTCREATE ...
            && com.mathworks.mde.editor.EditorOptions.getBuiltinEditor ~= 0)
        [errMessage, errID] = showFileNotFound(file, false);
    else
        openEditor(fullfile(path,fileName));
    end
else
    [errMessage, errID] = showFileNotFound(file, false);
end
handleError(errMessage, errID);

也许我的edit.m不好?或者有一个设置导致带有代码的新edit.m引发错误?有任何想法吗?

4

1 回答 1

3

如果在取消选中以下选项后编辑不存在的文件,我会在 2010a(edit.m 的第 57 行)中收到相同的错误消息:

文件 -> 首选项 -> 常规 -> 确认对话框 -> 编辑不存在的文件时提示

考虑到这一点,听起来您没有启用该选项?

于 2012-09-19T10:07:16.200 回答