Load multiple files on MATLAB

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by