How to solve NaN when using trapz?
37 views (last 30 days)
Show older comments
Vishnuvardhan Naidu Tanga
on 21 Jan 2022
Hello all,
I am trying to do a numerical integration using trapz from a excel data. But I am getting NaN. Please provide me with some guidence.
My code:
[num data raw] = xlsread('Flowratevel.xlsx');
col_1 = num(:,1);
col_2 = num(:,2);
col_3 = num(:,3);
col_4 = num(:,4);
col_5 = num(:,5);
col_6 = num(:,6);
col_7 = num(:,7);
col_8 = num(:,8);
col_9 = num(:,9);
col_10 = num(:,10);
A1 = pi*(num(:,1)).^2;
Q1 = A1.*num(:,2);
Int1 = trapz(A1, num(:,2));
A2 = pi*(num(:,3)).^2;
Q2 = A2.*num(:,4);
Int2 = trapz(A2, num(:,4));
A3 = pi*(num(:,5)).^2;
Q3 = A3.*num(:,6);
Int3 = trapz(A3, num(:,6));
A4 = pi*(num(:,7)).^2;
Q4 = A4.*num(:,8);
Int4 = trapz(A4, num(:,8));
A5 = pi*(num(:,9)).^2;
Q5 = A5.*num(:,10);
Int5 = trapz(A5, num(:,10));
0 Comments
Accepted Answer
Torsten
on 21 Jan 2022
Edited: Torsten
on 21 Jan 2022
[num data raw] = xlsread('Flowratevel.xlsx');
for i=1:size(num,2)
Num{i} = num(:,i)(~isnan(num(:,i)));
end
A1 = pi*Num{1}.^2;
Q1 = A1.*Num{2};
Int1 = trapz(A1, Num{2})
A2 = pi*Num{3}.^2;
Q2 = A2.*Num{4};
Int2 = trapz(A2, Num{4})
A3 = pi*Num{5}.^2;
Q3 = A3.*Num{6};
Int3 = trapz(A3, Num{6})
A4 = pi*Num{7}.^2;
Q4 = A4.*Num{8};
Int4 = trapz(A4, Num{8})
A5 = pi*Num{9}.^2;
Q5 = A5.*Num{10};
Int5 = trapz(A5, Num{10})
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!