导入多个没有标题的.mat文件

时间:2014-12-02 16:57:54

标签: matlab

enter image description here

目前正尝试通过以下脚本导入以下内容:

files = dir('C:\Users\student\Desktop\pattern hw4\train\*.mat');

for i=1:length(files)
    A = load(files(i)); % <-- line 7
end

我收到了错误:

Error using load
Argument must contain a string.

Error in hw4 (line 7)
    A = load(files(i));

添加.name后,我收到错误:

>> hw4
Error using load
Unable to read file 'class1_1.mat': no such file or directory.

Error in hw4 (line 7)
    A = load(files(i).name);

确定并找到最终答案/解决方案:

files = dir('C:\Users\student\Desktop\pattern hw4\train\*.mat');

dname='C:\Users\student\Desktop\pattern hw4\train\';

for i=1:length(files)
    fname=fullfile(dname,files(i).name);
    A = load(fname);
end

2 个答案:

答案 0 :(得分:2)

load命令需要文件名,而dir返回结构。尝试:

A = load(files(i).name);

答案 1 :(得分:1)

我认为您需要在第7行使用A = load(files(i).name);

files是一个结构数组