Daywise differences in array
Ahora está siguiendo esta pregunta
- Verá actualizaciones en las notificaciones de contenido en seguimiento.
- Podrá recibir correos electrónicos, en función de las preferencias de comunicación que haya establecido.
Se ha producido un error
No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.
0 votos
Comparte un enlace a esta pregunta
Respuesta aceptada
0 votos
Comparte un enlace a esta respuesta
11 comentarios
Comparte un enlace a este comentario
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.
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Más respuestas (0)
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Etiquetas
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- 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)
