Load multiple files on MATLAB

1 回表示 (過去 30 日間)
Alakesh Upadhyaya
Alakesh Upadhyaya 2023 年 2 月 21 日
回答済み: Voss 2023 年 2 月 21 日
So I have 10 data files and each data file contains X-cordinate and Y-cordinate of a ball for 100 frames.
The name of my files are like exp1.dat, exp2.dat, exp3.dat and so on till exp10.dat.
All of these files contain 2x100 data.
I have a code that calculates the velocity autocorelation of the ball for 100 time frames using the X and Y-cordinate.
What I want is to know how to write a code so that I can have a loop to load these files in sequence and caluclate the VACF for each of these data files and find mean of all 10 VACF ?

採用された回答

Voss
Voss 2023 年 2 月 21 日
n_files = 10;
VACF_all = zeros(n_files,100); % Pre-allocate a matrix to store all the VACF results.
% I assume the VACF you calculate for each file is a 1x100 vector (no idea if that's true)
for ii = 1:n_files
file_name = sprintf('exp%d.dat',ii);
% ...
% load the file, calculate VACF
% ...
VACF_all(ii,:) = VACF; % store VACF as the ii-th row of VACF_all
end
mean_VACF = mean(VACF_all, 1); % take the mean of all 10 VACFs

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by