在 Matlab 中使用 load 命令打开 .mat 文件时出错

发布于 2024-09-29 12:51:30 字数 417 浏览 0 评论 0原文

这是我的代码的一部分,我在其中输入 .mat 文件的名称,该文件与我的代码位于同一文件夹中。但是它无法识别文件名并给出错误:

“??? 使用 ==> load 时出错

无法读取文件“q.mat”:没有这样的文件或目录。”

q_type=input('Do you want to use q from "A", "B" or from a saved .mat file? Enter the exact name: ','s');
q_type=mat2str([q_type'.mat'])
load(q_type)

但是,如果我直接在命令窗口中使用加载命令,如下所示,那么它不会给出错误并加载文件:

load('q_A.mat')

为什么会这样?

Here's a part of my code where I am entering a name of the .mat file, which is located in the same folder as my code. However it does not identify the file name and gives an error:

"??? Error using ==> load

Unable to read file 'q.mat': No such file or directory."

q_type=input('Do you want to use q from "A", "B" or from a saved .mat file? Enter the exact name: ','s');
q_type=mat2str([q_type'.mat'])
load(q_type)

However if I use the load command in the command window directly as follow, then it gives no error and loads the file:

load('q_A.mat')

Why is it doing like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留一抹残留的笑 2024-10-06 12:51:30

这是使用模式对话框的更加用户友好的解决方案:

[fileName pathName] = uigetfile({'*.mat' 'MAT-files (*.mat)'}, 'Load Data', '.');
if pathName == 0, error('No file selected'), end
load( fullfile(pathName,fileName) )

您可以根据需要随意自定义它。

Here's a more user-friendly solution using a modal dialog:

[fileName pathName] = uigetfile({'*.mat' 'MAT-files (*.mat)'}, 'Load Data', '.');
if pathName == 0, error('No file selected'), end
load( fullfile(pathName,fileName) )

feel free to customize it as needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文