# How can i measure the power from my plot in the scope?

8 views (last 30 days)
Peter Lyngbye on 18 Oct 2022
Answered: Amith on 26 May 2023 at 5:56
Hey,
I have two plots in my scope, and i want the total power from each of these plots. How can i do this? :)
I tried the measuremnt button in the scope, but it does not show me the total power.

Amith on 26 May 2023 at 5:56
Hi,
As per my understanding you wanted to find the total power from the plots.
To calculate the total power from a plot, you can use the trapezoidal rule to numerically integrate the area under the curve. Here's an example code snippet that demonstrates how to calculate the total power from a plot using the `trapz` function:
% Generate some sample data
x = linspace(0, 2*pi, 1000);
y = sin(x);
plot(x,y)
% Calculate the total power using the trapezoidal rule
dt = x(2) - x(1);
total_power = trapz(x, y.^2) * dt;
In this example, we first define some sample data as a sine wave. We then calculate the total power by squaring the y-values, using the `trapz` function to numerically integrate the area under the curve, and then multiplying by the time step `dt`.
You can use similar function to find the area under the curve and hence find the total power of the plot.
You can retrieve the data points of a plot from the scope block in Simulink by using the "To Workspace" block. Here's how you can do it:
1. In your Simulink model, locate the signal that is connected to the input of the scope block.
2. Add a "To Workspace" block next to the output of the signal.
3. Double-click on the "To Workspace" block to open its parameters window.
4. In the "Save format" field, select "Array" to save the data points as an array.
5. In the " Variable name: " field, enter a name for the array. This will be the variable name that you will use to access the data in MATLAB.
6. Run the simulation.
7. Once the simulation is complete, the data points of the signal in the scope block will be saved as a variable in the MATLAB workspace. You can access these data points by typing the name of the variable you specified in step 5

### Categories

Find more on General Applications in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!