Average range when value is reached
이전 댓글 표시
Hello,
I have a tough situation in hands.
File format (sample file attached)
day_of_year | solar height | d1 | d2 | d3 | d4
I need to apply a correction to d1 to d4 based on solar height.
For each day I need to fing the average value of d1, d2, d3 and d4 for:
1- once solar height hits -18 (degrees) in the morning I need to average the previous 60 data values (if this happens on cell 101, i need the average of cells 40 to 100)
2 -once solar height hits -18 (degrees) in the afternoon/night I need to average the following 60 data values
3 - Obtain the average value between 1 and 2 for each day of the year.
Note: Solar Height is negative before sunrise and after sunset, being positive during the day.
I don't have really an idea on how to proceed from here...
This file has 59 days, so the result would be a matrix 59*4 results.
thanks for the attention
댓글 수: 1
Guillaume
2019년 6월 28일
Note that cell 40 to 100 is 61 cells not 60.
채택된 답변
추가 답변 (1개)
Shubham Gupta
2019년 6월 28일
I assumed that you have test_data in a mat file, for this answer I am assuming the data stored in the variable named 'TestData'. I think you should achieve the desired result with the following code :
Ind = find(abs(TestData(:,2)+18)<0.097); % Finding indices that are close to Solar height of -18 (deg)
d_SH = [0;diff(TestData(:,2))]; % Variation in solar height
%% Loop to store average values
for i=1:length(Ind)
j = Ind(i);
if d_SH(j)>0 % If solar height is increasing ( Sunrise )
Out(i,:) = mean(TestData(j-60:j,3:6));
else % If solar height is decreasing ( Sunset )
Out(i,:) = mean(TestData(j:j+60,3:6));
end
end
%% Averaging Sunrise and Sunset data
for k=1:length(Out)/2
Desired_out(k,:) = mean(Out(2*k-1:2*k,:));
end
댓글 수: 1
카테고리
도움말 센터 및 File Exchange에서 Gravitation, Cosmology & Astrophysics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!