Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to load multiple .mat files into two different groups

1 次查看(过去 30 天)
I'm trying to make two groups out of the processed participants, one controle group (freqct) and one patient group (freqpt). I have an active path to the folder in which files are.
When I run this code I get the following error code:
Error using load
Cannot read file I:\preprocessed\Sub10.mat.
Error in Code2_1 (line 93)
freqct = load(fullfilename);
This is the code I have written. The last couple of hours I am bashing my head against the code and have tried numerous things, none worked.
clear all
sbjs = dir('Sub*.mat');
for i = 1:8
freqct{i} = load(sbjs(i).name);
end
clear i
for i = 9:length(sbjs)
n = 1
freqpt{n} = load(sbjs(i).name);
n = n+1;
end
This is an overview of the files I want to load. In every file (Sub1.mat till Sub15.mat) there are the same files as in Sub10.mat (see below)

回答(1 个)

KSSV
KSSV 2020-8-11
First nine will be files Sub1,...Sub9 and the rest will be from Sub10.
  6 个评论
KSSV
KSSV 2020-8-11
编辑:KSSV 2020-8-11
clear all
matfiles = dir('Sub*.mat');
N = length(matfiles) ;
data = cell(N,1) ;
for i = 1:N
S = load(matfiles(i).name);
data{i} = S ;
end
data is a cell where each cell has a structure. First 9 of data are files from 1 to 9 and than rest are from 10.
Joran Muller
Joran Muller 2020-8-11
I get the same error code again, it can't read Sub10 or Sub2. I could not load Sub10 when there were already variables with the same name in the workspace, so I made it deleted everything. This also did not work. I have the feeling something goes wrong with placing sub02 into S, but what I don't know.
%%
matfiles = dir('Sub*.mat');
N = length(matfiles);
datas = cell(N,1);
%%
for i = 1:N
S= load(matfiles(i).name);
datas{i} = S;
clear badcomp
clear cfg
clear comp
clear data
clear dataclean
clear datads
clear dataica
clear fft_data_planar
clear freq_combined
clear planar
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by