# Calculating area under curve from simulink

39 visualizaciones (últimos 30 días)
Peter Lyngbye el 16 de Dic. de 2022
Respondida: Santosh Fatale el 21 de Dic. de 2022
Hello,
I have a curve simulink that i have used the "to workspace" block on.
Now i got the curve in workspace but how can i find the area under the curve between two X(time) points?
And is there a way to tell how many "points" u integrate, meaning how many points there actually are used to get the area.
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Santosh Fatale el 21 de Dic. de 2022
Hi Peter,
You can calculate the area under the curve using the "trapz" function. To find the area over a finite interval and the non-unit spacing between data points, use following syntax:
Area = trapz(X,Y)
Here input X is the point spacing (x-coordinates) for data points present in input Y.
For the variable created from Simulink, the point spacing is equivalent to sample time used in Simulink. You could get sample times for the curve from variable "tout". If variable is created as time series variable, then the first column represents data point spacing with respect to time.
Following code demonstrates this:
Create a breakpoint at Line 30 and execute the code till breakpoint. You could see "out" variable in workspace. Execute following command in command window.
>> varCurve = out.simoutToWorkspace;
>> X = varCurve.Time;
>> Y = varCurve.Data;
>> Area = trapz(X(1:11), Y(1:11))
Area =
13.7823
Note that for accurate area, you need higher samples in interested interval.
To fix the interval for integration, choose suitable input X and corresponding data points Y.
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

R2022b

### Community Treasure Hunt

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

Start Hunting!