Matlab Code to calculate total energy consumed in given time.

49 views (last 30 days)
Hello MathWorks community.
I am absolutely new to MatLab (just started learning yesterday for a project) so i hope you will tolerate my dumbness.
So i have a file from Current mesuring sensor. Column 1 is time in Seconds. Column 2 is Current measured at that time (not important). Column 3 is Power consumed in watts (important). Now my question is, how to calculate total power consumed in the timeframe of the spreadsheet. if the machie ran for 15 seconds, what was the power consumption.
If i am missing out any info, let me know. Thank you for all the help. excited to learn through problems.

Accepted Answer

Askic V
Askic V on 25 Jan 2023
Energy is just an integral of power over time. You can use cumtrapz function.
This is probably what you need:
A = xlsread('X_F40000.xlsx');
t = A(:,1);
P = A(:,3);
E = cumtrapz(t, P);
plot(t,P)
hold on
plot(t,E)
legend('Power', 'Energy');
  2 Comments
SUNIL KUMAR
SUNIL KUMAR on 25 Jan 2023
oh yes. that works for the plot. thank you very much. quite easy to understand. i can play around with it now.
is there any way to get the final number for energy consumption as a number? or as a string .
tempText = ['total energy consumed is ',num2str(E),'W/h']
Askic V
Askic V on 25 Jan 2023
Yes, final number for energy consumption is E(end), i.e. last element of E.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!