필터 지우기
필터 지우기

Saving data in a FOR loop

조회 수: 4 (최근 30일)
MILLER BIGGELAAR
MILLER BIGGELAAR 2020년 5월 21일
댓글: Tommy 2020년 5월 21일
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)

채택된 답변

Tommy
Tommy 2020년 5월 21일
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
MILLER BIGGELAAR
MILLER BIGGELAAR 2020년 5월 21일
Yes it does thank you so much!
Tommy
Tommy 2020년 5월 21일
Happy to help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by