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!