Filter löschen
Filter löschen

Saving data in a FOR loop

4 Ansichten (letzte 30 Tage)
MILLER BIGGELAAR
MILLER BIGGELAAR am 21 Mai 2020
Kommentiert: Tommy am 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)

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by