Daywise differences in array
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
0 개 추천
채택된 답변
댓글 수: 11
Hi @Poulomi,
To address your request for analyzing the rainfall data and determining whether the difference in rainfall values exceeds 30 mm within a 24-hour period, we need to modify the approach slightly. Your initial code iterates through each time point but only checks the next day's value, rather than considering all values within the previous 24 hours. This requires a more efficient method that avoids nested loops. You can utilize MATLAB’s capabilities with timetables to streamline this process. The following code implements a more efficient approach using logical indexing and vectorized operations:
% Input data as provided R = [1982 5 1 3 25; 1982 5 1 6 30; 1982 5 1 12 35; 1982 5 1 18 40; 1982 5 2 0 45; 1982 5 2 3 45; 1982 5 2 6 50; 1982 5 2 12 55; 1982 5 2 18 55; 1982 5 3 0 60; 1982 5 3 3 65; 1982 5 3 6 80; 1982 5 3 12 90; 1982 5 3 18 105; 1982 5 4 0 115; 1982 5 4 3 115; 1982 5 4 6 115; 1982 5 4 12 115; 1982 5 4 18 115; 1982 5 5 3 30];
% Create a timetable
ttR = timetable(datetime(R(:,1:3)) + hours(R(:,4)), R(:,5),
'VariableNames',
{'Rainfall'});
% Initialize variables to hold results t = []; r = [];
% Loop through each time point for i = 1:height(ttR) % Define the time window for the previous 24 hours startTime = ttR.Time(i) - caldays(1); endTime = ttR.Time(i);
% Find all rainfall values within this time window
rainInWindow = ttR.Rainfall(ttR.Time >= startTime & ttR.Time <
endTime); if ~isempty(rainInWindow)
% Calculate the difference between current rainfall and
maximum in window
dRF = max(rainInWindow) - ttR.Rainfall(i); if dRF > 30
t = [t; ttR.Time(i)];
r = [r; dRF];
end
end
end% Create result timetable
ttDRF = timetable(t, r, 'VariableNames', {'24hr_Rainfall'});
ttDRF.Properties.DimensionNames(1) = {'Begin_Date'};
% Display results disp(ttDRF);
first timetable is created from your data which allows for easier time-based indexing. For each time point, we calculate the start and end of the previous 24-hour window, using logical indexing to extract all rainfall values within that time window, computing the difference between the maximum rainfall in that window and the current time's rainfall. If the difference exceeds 30 mm, we store the timestamp and difference.
Feel free to run this code snippet in your MATLAB environment, and it should yield results based on your specified criteria for identifying significant rainfall differences over a defined time frame.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
