Azzera filtri
Azzera filtri

Saving data in a FOR loop

4 visualizzazioni (ultimi 30 giorni)
MILLER BIGGELAAR
MILLER BIGGELAAR il 21 Mag 2020
Commentato: Tommy il 21 Mag 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)

Risposta accettata

Tommy
Tommy il 21 Mag 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 Commenti
MILLER BIGGELAAR
MILLER BIGGELAAR il 21 Mag 2020
Yes it does thank you so much!
Tommy
Tommy il 21 Mag 2020
Happy to help!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by