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!
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!