How can I read multiple mat files and perform ttest2 function?
2 次查看(过去 30 天)
显示 更早的评论
hi!
I have 108 mat files and I must go through them and test them by 2. The thing is, I haven't find a way to include all of them, without having to call them seperetaly,and at the same time storing the results for each comparison.( i am doing a ttest for each pair of files). Obvious a loop will be the answer but haven't any idea how to put the files in the loop.
Thank you!
0 个评论
采纳的回答
dpb
2020-11-24
编辑:dpb
2020-11-24
Arrange the name convention so they will sort in the desired sequence and can process by twos -- then
d=dir(fullfile('directory','appropriatename*.mat')); % return the list of files
for i=1:2:numel(d)
data1=importdata(fullfile(d(i).folder,d(i).name));
data2=importdata(fullfile(d(i+1).folder,d(i+1).name));
% do whatever with the two files here before going on...save the results wanted
end
0 个评论
更多回答(2 个)
KSSV
2020-11-24
This question has been discussed to death. A simple search will give you lot of links.
matFiles = dir('*.mat') ;
N = length(matFiles) ;
for i = 1:N
thisFile = matFiles(i).name ;
load(thisFile) ;
% Do what you want
end
0 个评论
Mathieu NOE
2020-11-24
hello
my single for loop code example
enjoy
n = 108;; % number of files
s = 2; % create combination of 2 elements
[comb,nComb]=makecomb(n,s) % combinations
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This functions evaluates all possible combinations of N elements
% taken by sets of S elements.
% Usage: [comb,nComb]=makecomb(number_of_elements,size_of_each_combination);
% Return values:
% comb: a S x nComb matrix where each column of S rows contains a possible
% combination of N elements;
% nComb: number of evaluated combinations (and number of columns of comb);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ci = 1:nComb
file1 = ['file' num2str(comb(1,ci))];
file2 = ['file' num2str(comb(2,ci))];
% your code here
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!