开发者

Error using load command to open .mat file in Matlab

开发者 https://www.devze.com 2023-01-21 07:24 出处:网络
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:

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 directo开发者_Go百科ry."

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号