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!