I imported a set of data into matlab and have plotted the curve. However, I do not know how to use trapz to find the area under the curve.

 채택된 답변

the cyclist
the cyclist 2021년 10월 8일

0 개 추천

I did not open your text file, but assuming you got that plot using
plot(x,y)
then it should be as easy as
trapz(x,y)

댓글 수: 3

jjxc
jjxc 2021년 10월 8일
i used trapz(x,y) and i got this error
"Dimension argument must be a positive integer scalar within indexing range."
% Load data
data = readtable('discharge 30mA.txt');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
% Drop the last point, which is NaN
x = data{1:end-1,1};
y = data{1:end-1,2};
% Plot the data
figure
plot(x,y)
% Calculate the area
area = trapz(x,y)
area = 813.2263
jjxc
jjxc 2021년 10월 8일
oh okay i can understand the steps. Thank you for the help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2021년 10월 8일

댓글:

2021년 10월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by