gpt4 book ai didi

Matlab 不会使用编辑命令创建文件

转载 作者:太空宇宙 更新时间:2023-11-03 20:02:50 24 4
gpt4 key购买 nike

当我进入

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 抛出错误?有任何想法吗?

最佳答案

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

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

请注意,您似乎没有启用该选项?

关于Matlab 不会使用编辑命令创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12486442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com