Matlab无法使用edit命令创建文件

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文件抛出错误?有什么想法吗?

2
你可能有另一个名为 edit 的文件,它掩盖了内置函数。要检查,请运行 which edit - slayton
1
你的edit.m文件中的第57行在哪里? - Oli
1个回答

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

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

因此,听起来您没有启用该选项?


这对我有效,并且似乎是一个错误/设计不良的UI。当然,如果我取消选中复选框,这意味着我不想被提示创建新文件,而不是在尝试时抛出错误。 - Bill Cheatham

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接