Reputation: 3139
I am working in MATLAB and I have 2 arrays. Current and Voltage flowing in a capacitance when I connect and disconnect it from the voltage. Of course I have a time_stamp
vector in which there are all the samples of time at which I made the measurements.
I want to plot the power and energy associated to those arrays.
For the power I just need to do:
z1 = plot(time_stamp_ms,measured_voltage.*current,'-b','LineWidth',1);
Right?
Instead, how can I do to plot the energy?
Thanks for your time.
Upvotes: 2
Views: 237
Reputation: 45752
I think your power looks right. For energy, it's just power multiplied by time right so:
dt = diff(time_stamp_ms);
power = measured_voltage.*current;
energy = dt.*power(2:end);
well this gives the energy used between each time step. If you wanted the cumulative energy then:
energy_cum = cumsum(energy)
Upvotes: 4