Daywise differences in array
Sie verfolgen jetzt diese Frage
- Aktualisierungen können Sie in Ihrem Feed verfolgter Inhalte sehen.
- Je nach Ihren Kommunikationseinstellungen können Sie auch E-Mails erhalten.
Es ist ein Fehler aufgetreten
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
0 Stimmen
Teilen Sie einen Link zu dieser Frage
Akzeptierte Antwort
0 Stimmen
Teilen Sie einen Link zu dieser Antwort
11 Kommentare
Teilen Sie einen Link zu diesem Kommentar
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.
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Weitere Antworten (0)
Kategorien
Mehr zu Data Type Conversion finden Sie in Hilfe-Center und File Exchange
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)
