Saving data in a FOR loop

1 view (last 30 days)
MILLER BIGGELAAR
MILLER BIGGELAAR on 21 May 2020
Commented: Tommy on 21 May 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)

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!