Calculating area under curve from simulink
42 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Santosh Fatale
2022 年 12 月 21 日
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:
>> openExample('simulink/OutputSimulationDataWithBlocksExample')
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.
Refer the documentation of “trapz” function and "timeseries" for more information about numerical integration.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!