Cumtrapz in a table does not work with datetime

조회 수: 6 (최근 30일)
Noush
Noush 2022년 1월 5일
댓글: Star Strider 2022년 1월 5일
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