# I want find mean of out.txt file such that this file is replaces at every iteration and hence values changed.

2 vues (au cours des 30 derniers jours)
Adeline War le 22 Nov 2022
Commenté : Mathieu NOE le 22 Nov 2022
Hello everyone.
How are you?
I have a question here. With every iteration I have an output.txt file generated such that values vary with each iteration. Now I want to find the mean of each iteration till 100 iterations and store the mean in some variable ( say m1 to m100) or if there is any other representation in a txt or excel file also. Please help me how to code it such that my mean is calculated based on the present file generated.
I have attached here two output files (out) for two iterations but this can go to 100. You can try with 5 such different output files.
Thank you,
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Mathieu NOE le 22 Nov 2022
I am not sure to understand ...

Connectez-vous pour commenter.

### Réponses (1)

Voss le 22 Nov 2022
Let's say you have 100 iterations, and data is a vector containing the numbers written to file on each iteration. Then to calculate the mean of data on each iteration and store those means, you could say:
n_iterations = 100;
% initialize a vector to store the means:
data_means = zeros(1,n_iterations);
for ii = 1:n_iterations
% ...
% whatever code calculates 'data'
% ...
% store the mean of the current 'data' in element ii of 'data_means':
data_means(ii) = mean(data);
end
Or, if you don't know how many iterations there will be:
% initialize a vector to store the means:
data_means = [];
while true % some condition that will eventually be false
% ...
% whatever code calculates 'data'
% ...
% store the mean of the current 'data' in a new element of 'data_means':
data_means(end+1) = mean(data);
end
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by