For loop to evaluate Root Mean Square

조회 수: 6 (최근 30일)
Emiliano Ascenzi
Emiliano Ascenzi 2020년 4월 9일
댓글: Emiliano Ascenzi 2020년 4월 11일
For every row of C I want to find all the elements in column A that are in a time window (centered on the first element of column A at the first iteration) of 4 minutes. Second iteration is find all the elements in column A that are in a time window (centered on the second element of column A) of 4 minutes. And so on for all rows of C table.
After doing that, I want to delete all outputs that are equal mantaining one for type and compute root mean square on every output remaining.
Attached a dummy table for the code, I think this is relatively easy to do with a for loop but I don't know how to implement it, other solution are well accepted,
Thanks in advance
  댓글 수: 6
Rik
Rik 2020년 4월 11일
Your code has multiple issues, so it will not run with the data you provided. Either provide working code (and explain how it should be sped up/optimized/extended), or provide a full example where you describe the steps you want to take in words.
Do you want to select all values in a 4-minute window, essentially performing a sliding window operation? If so, why would you need Tstart and Tstop?
Emiliano Ascenzi
Emiliano Ascenzi 2020년 4월 11일
편집: Emiliano Ascenzi 2020년 4월 11일
I know my code isn't working, i posted it only to explain what i need. I try to describe it in words.
For every row of C I want to find all the elements in column A that are in a time window (centered on the first element of column A at the first iteration) of 4 minutes. Second iteration is find all the elements in column A that are in a time window (centered on the second element of column A) of 4 minutes. And so on for all rows of C table.

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

답변 (1개)

Jeff Miller
Jeff Miller 2020년 4월 10일
I don't really understand what you mean by conditions, but maybe you can get what you want by thinking of a 2-step process where the first step is to pick out the rows you want and the second step is to get the rms. This code snippet illustrates it:
stopTime = datetime(2020,1,5,8,15,0); % set these according to your conditions, possibly in for loop
startTime = datetime(2020,1,5,7,45,0);
wantRows = (T>startTime) & (T<stopTime);
y = rms(x(wantRows));
  댓글 수: 8
Emiliano Ascenzi
Emiliano Ascenzi 2020년 4월 11일
편집: Emiliano Ascenzi 2020년 4월 11일
I don't think the code is doing what I need. If you try to execute it you'll have an output with only one value repeated for every row. But for how the data is build (3 different time arrays concatenated that are far more than 2 minutes each other) I expect at least 3 different values, but there is only one
Emiliano Ascenzi
Emiliano Ascenzi 2020년 4월 11일
I checked the code, there is an error in isbetween, the vector to analyze is C.T and not C.T(i). This is the right code.
Thank you all
rmsA = zeros(height(C),1);
for i=1:height(C)
tf = isbetween(C.T,C.T(i)-minutes(2),C.T(i)+minutes(2));
xA = C.A(tf);
rmsA(i) = rms(xA);
end

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

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by