Daywise differences in array
Vous suivez désormais cette question
- Les mises à jour seront visibles dans votre flux de contenu suivi.
- Selon vos préférences en matière de communication il est possible que vous receviez des e-mails.
Une erreur s'est produite
Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.
0 votes
Partagez un lien vers cette question
Réponse acceptée
0 votes
Partagez un lien vers cette réponse
11 commentaires
Partagez un lien vers ce commentaire
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.
Partagez un lien vers ce commentaire
Partagez un lien vers ce commentaire
Partagez un lien vers ce commentaire
Partagez un lien vers ce commentaire
Partagez un lien vers ce commentaire
Partagez un lien vers ce commentaire
Partagez un lien vers ce commentaire
Partagez un lien vers ce commentaire
Partagez un lien vers ce commentaire
Partagez un lien vers ce commentaire
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
