Effacer les filtres
Effacer les filtres

Saving data in a FOR loop

4 vues (au cours des 30 derniers jours)
MILLER BIGGELAAR
MILLER BIGGELAAR le 21 Mai 2020
Commenté : Tommy le 21 Mai 2020
Hi, I know there are a lot of answers out here for this one already but I have not been successful in transferring the results into my application.
My code is as follows
n=2:50;
for a = (t_r>=Tvec(n)-dt/2) & (t_r<Tvec(n)+dt/2);
b = mean(Ch0_Incident_WP(a));
end
So a is finding a specific set of numbers using a vector Tvec which has pre defined variables in vector form, afterwards b is finding the average from the data according to a
An example would be Tvec(2) would find the mean average of Ch0_Incident_WP at point a where we are using the second Tvec number.
My issue is that of course will only save the last lot of data (50th), I have tried adding the results to an array but I haven't succeeded. I need all iterations of data from 2:50 (n)

Réponse acceptée

Tommy
Tommy le 21 Mai 2020
Does this work?
n=2:50;
b = zeros(numel(n),1);
for i = 1:numel(n)
a = (t_r>=Tvec(n(i))-dt/2) & (t_r<Tvec(n(i))+dt/2);
b(i) = mean(Ch0_Incident_WP(a));
end
  2 commentaires
MILLER BIGGELAAR
MILLER BIGGELAAR le 21 Mai 2020
Yes it does thank you so much!
Tommy
Tommy le 21 Mai 2020
Happy to help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by