Cumtrapz in a table does not work with datetime

4 Ansichten (letzte 30 Tage)
Noush
Noush am 5 Jan. 2022
Kommentiert: Star Strider am 5 Jan. 2022
Hi,
I have a table with loading power values (column 4) of a battery and unloading power values (column 5). My first column are datetime values, as my power values are displayed for a whole week.
Now I would like to plot column 4 and 5 over the first one, but I first need to work in a condition that defines that the sum of the unloading power (so the energy value of my battery) cannot surpass the loading one and vice versa.
I have tried to do it with this code:
A15 = cumtrapz(BigTable.Ausgelegte_Ladeleistung);;
A16 = cumtrapz(BigTable.Ausgelegte_Entladeleistung);
for i=1:168
if -A16(i) > A15(i)
BigTable{i,5} = 0;
end
end
It seems to work at first, but after a few rows the unloading power just keeps being zero. I meant to define with my for loop that its always considered for the current row (so for i), but somehow that did not work out.
How can I correct?
Thank you for your help!

Antworten (1)

Star Strider
Star Strider am 5 Jan. 2022
Use the datenum function to convert the dates and times to decimal days and decimal fractions of days to use as the ‘x’ vector in cumtrapz. It would likely be necessary to subtract the first value in the vector from the rest of the vector to normalise it to the start time and provide appropriate results.
It may also be possible to use a duration array with cumulative hours. (The datenum approach is likely easier.)
  2 Kommentare
Noush
Noush am 5 Jan. 2022
I have tried the datenum input in cumtrapz already, that does not work. Now I tried again substracting the first value as you suggested, so like this:
x = datenum(BigTable{:,1})-datenum(BigTable{1,1});
A15 = cumtrapz(x,BigTable.Ausgelegte_Ladeleistung);;
A16 = cumtrapz(x,BigTable.Ausgelegte_Entladeleistung);
that also does not work. My plot keeps on coming out like this (as you can see A16 only appears on the first day):
Star Strider
Star Strider am 5 Jan. 2022
The datenum approach works.
The rest of the code (and the data and how you want to work with it that I don’t have to work with so I can’t experiment with it) are the problem.
.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Time Series Objects finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by