Matlab Code to calculate total energy consumed in given time.

49 ビュー (過去 30 日間)
SUNIL KUMAR
SUNIL KUMAR 2023 年 1 月 25 日
コメント済み: Askic V 2023 年 1 月 25 日
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.

採用された回答

Askic V
Askic V 2023 年 1 月 25 日
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 件のコメント
SUNIL KUMAR
SUNIL KUMAR 2023 年 1 月 25 日
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 2023 年 1 月 25 日
Yes, final number for energy consumption is E(end), i.e. last element of E.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by