Cumtrapz in a table does not work with datetime

6 次查看(过去 30 天)
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!

回答(1 个)

Star Strider
Star Strider 2022-1-5
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 个评论
Noush
Noush 2022-1-5
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 2022-1-5
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.
.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by