How to use imported data with trapz( )

Hi, I have imported two columns of a csv data file into Matlab and are contained in one table. The columns are labeled Times and DragForceN. I want to use them in trapz(x,y). My end goal here is to obtain the work done by drag. I keep getting an error message and I cannot figure out how to fix it. Any help would be appreciated.
x = importdata('Times.csv');
y = importdata('DragForceN');
dragWork_H13 = trapz(x,y)

댓글 수: 4

Eric Sofen
Eric Sofen 2022년 9월 19일
Your description "two columns...contained in one table" doesn't match with the code that shows imports to two separate variables, x and y.
It would also be helpful if you gave us the complete text of the error message. Are x and y the same size?
I apologize, I have now uploaded the error image and yes it is two variables: time, and drag
dpb
dpb 2022년 9월 19일
Well, the error says importdata couldn't open the file; you didn't even get to the second step...it didn't say it couldn't find the file; so apparently there is such a file but it wasn't a valid text file as the .csv extension would suggest it should be.
But, we can't tell what went wrong -- attach the file so somebody can try to duplicate the issue/see what the file really does contain.
I have attached the csv file I imported into MATLAB. I only run the values of Time and Drag up to Apogee which is up to time=10.7 seconds

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

답변 (1개)

KSSV
KSSV 2022년 9월 20일

0 개 추천

T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1129920/H182%20Drag.csv') ;
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.
x = T.(1) ;
y = T.(2) ;
% fill the NaN's in the data
x = fillmissing(x,'linear') ;
y = fillmissing(y,'linear') ;
%
trapz(x,y)
ans = 122.9553

카테고리

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

제품

릴리스

R2022b

질문:

2022년 9월 19일

답변:

2022년 9월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by