Filter löschen
Filter löschen

Load multiple files on MATLAB

4 Ansichten (letzte 30 Tage)
Alakesh Upadhyaya
Alakesh Upadhyaya am 21 Feb. 2023
Beantwortet: Voss am 21 Feb. 2023
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 ?

Akzeptierte Antwort

Voss
Voss am 21 Feb. 2023
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

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by