How can I read multiple mat files and perform ttest2 function?
Show older comments
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!
Accepted Answer
More Answers (2)
KSSV
on 24 Nov 2020
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
Mathieu NOE
on 24 Nov 2020
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
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!