How to SUMIF similar to Excel
조회 수: 29 (최근 30일)
이전 댓글 표시
Hi I have a table with the following values and want to do SUMIF similar to excel and save data to a new table (Table T below). I tried to get all power values that occur at the same time to be summed, so that I can plot one curve. Not sure where this is going wrong.
DateTime Power
____ _____
Feb 1 2022 01:00 4
Feb 1 2022 02:00 5
Feb 1 2022 02:00 2
Feb 1 2022 03:00 1
Desired Result:
DateTime Power
____ _____
Feb 1 2022 01:00 4
Feb 1 2022 02:00 7
Feb 1 2022 03:00 1
t1 = datetime(2022,02,01,0,1,0);
t2 = datetime(2022,02,01,0,5,0);
totalminutes = minutes(t2-t1);
t = (t1:minutes(1):t2);
for i = 1:totalminutes;
if T.DateTime == t(1,i);
R = table(T.DateTime,sum(T.Power));
else
end
댓글 수: 0
답변 (1개)
Stephen23
2022년 5월 3일
"Not sure where this is going wrong."
Reinventing the wheel by writing lots of loops, and ignoring the inbuilt tools.
dt = datetime(2022,2,1,[1;2;2;3],0,0);
pw = [4;5;2;1];
tbl = table(dt,pw)
out = groupsummary(tbl,"dt","sum")
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Waveform Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!