calculating the difference between daily precipitation values

9 visualizaciones (últimos 30 días)
Shahidh Shaik
Shahidh Shaik el 26 de Oct. de 2021
Comentada: Jon el 1 de Nov. de 2021
hello i am shahidh and i have dataset like mentioned below
13.01.1941 07:30 4.1
14.01.1941 07:30 4.9
15.01.1941 07:30 4.9
16.01.1941 07:30 4.9
17.01.1941 07:30 4.9
18.01.1941 07:30 11.3
.
.
10.10.2021 07.30 23000
and i wated to calulate the daily value differences for this dataset and i wanted to plot the graph like on the x axis year and time) on y axis precipitation so does any one have an idea how to do that.
thank you

Respuestas (1)

Jon
Jon el 26 de Oct. de 2021
Editada: Jon el 26 de Oct. de 2021
I am not sure how you are defining "daily value differences". If you want to know the difference between succesive values you can use MATLAB's diff function. So if you have a vector (e.g. your second column of data) of values x and want to know the change from one day to the next (assuming samples are taken on successive days) you could use
delta = diff(x)
Here is a little bit of example code that might give you some ideas about how to work with dates and times
% assign time values
timevals = {'13.01.1941 07:30'
'14.01.1941 07:30'
'15.01.1941 07:30'
'16.01.1941 07:30'
'17.01.1941 07:30'
'18.01.1941 07:30' };
% assign daily precipitation values
dailyPrecip = [ 4.1
4.9
4.9
4.9
4.9
11.3];
% convert times to MATLAB datetime vector
t = datetime(timevals,'InputFormat','dd.MM.yyyy hh:mm');
% find differences in daily rainfall amounts
delta = diff(dailyPrecip);
% plot result, note first delta corresponds to second day and so on
% so we start time at second day
figure
plot(t(2:end),delta);
  3 comentarios
Jon
Jon el 27 de Oct. de 2021
I'm not sure what format your data file is in. If it is in a Excel Workbook .xlsx file or a .csv file you can use the following to import the data into a MATLAB table. So for example if your data were in a file called precipDat.xlsx
T = readtable('precipDat.xlsx')
if the data were in a file called precipDat.csv use:
T = readtable('precipDat.csv')
Assuming there are no headers, naming the columns this will give you a table with two columns called Var1 and Var2, you could then follow the original steps with a little modification.
t = datetime(T.Var1,'InputFormat','dd.MM.yyyy hh:mm');
delta = diff(T.Var2)
plot(t(2:end),delta)
You can get more info on the readtable command by typing doc readtable on the MATLAB command line.In particular if your data has headers you can import the data into a table with the columns named as they are in the data file. You can also skip intial rows and the like. I think you can see how to modify my example from that point, but let me know if you get stuck
Jon
Jon el 1 de Nov. de 2021
Were you able to get this working. Did you have questions?

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by