# How to solve NaN when using trapz?

34 ビュー (過去 30 日間)
Vishnuvardhan Naidu Tanga 2022 年 1 月 21 日

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:
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));

サインインしてコメントする。

### 採用された回答

Torsten 2022 年 1 月 21 日

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})
##### 3 件のコメント表示 2 件の古いコメント非表示 2 件の古いコメント
Vishnuvardhan Naidu Tanga 2022 年 1 月 24 日
Hello @Torsten
Thank you it worked.

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!